Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UITableView和数据源_Objective C - Fatal编程技术网

Objective c UITableView和数据源

Objective c UITableView和数据源,objective-c,Objective C,我正在尝试在UITableView中添加数据源。我尝试了以下方法,但不幸的是没有成功: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 8; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtInde

我正在尝试在UITableView中添加数据源。我尝试了以下方法,但不幸的是没有成功:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 8;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Set the data for this cell:

    cell.textLabel.text = [_classCellview objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = @"One";
     cell.detailTextLabel.text = @"Two";



    // set the accessory view:
    cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}
cell.textlab.text=[\u classCellview objectAtIndex:indexPath.row]


您告诉表有8个部分,但在填充单元格时没有考虑索引路径中的
部分。索引路径(在表视图的情况下)有两个值:一个
部分
和一个
。你需要他们都知道你在处理什么细胞。因此,您可能会在表的每个部分重复相同的内容。(如果你能确切地告诉我们问题是什么,那会有帮助。)

是否调用了cellForRowAtIndexPath?你所说的“不工作”是什么意思?我没有看到
tableView:numberOfRowsInSection:
的实现,这是
UITableViewDataSource
所必需的。这是我的tableView:numberOfRowsInSection-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{//返回节中的行数。Return self.classCellview.count;}我显示了表,但我想标记字段“一”和“二”在这种情况下,请查看您对单元格的详细信息标签所做的操作。您正在将
@“one”
分配给它的
文本
属性,然后在下一行将
@“two”
分配给同一标签。一个标签一次只能有一个值——如果需要
一两个
,则应首先组合字符串并将结果分配给标签。