Objective c UITableView和数据源
我正在尝试在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
- (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”
分配给同一标签。一个标签一次只能有一个值——如果需要一两个
,则应首先组合字符串并将结果分配给标签。