我想知道如何在表格的每个单元格中显示不同的数据。
在我的情况下,我有一个有4行的uitable。我想在第一行,第二行地址,第三行电话号码中显示名称。 ,第4行电子邮件。有什么建议吗?
...谢谢
答案 0 :(得分:3)
实施tableView:cellForRowAtIndexPath:
方法后,您可以在indexPath.row
值上添加条件。这假设您为数据的每一行使用相同的视图类型。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
switch (indexPath.row) {
case 0:
cell.textLabel.text = /* you data goes here */;
break;
case 1:
cell.textLabel.text = /* you data goes here */;
break;
/* your additional cases go here */
}
return cell;
}
如果您希望每行有不同的表视图单元格类型,则必须为每一行提供不同的单元格标识符,并使用{{1}实例化具有所需特定单元格类型的UITableViewCell
}语句或switch
语句。
答案 1 :(得分:0)
将数据存储在一个数组suppose-arr中 在cellForRowAtIndexPath方法中写 - > cell.textLable.text = [arr objectAtIndex:indexPath.row];