我有很多单元格,我想枚举它们。所以第一个单元格的标签为“1”,第二个单元格的标签为“2”等。 我试过了
- (DataManageTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *objectDate = [timeResultArray objectAtIndex:(long)indexPath.row];
DataManageTableViewCell *cell = [timeOfScheduleTableView dequeueReusableCellWithIdentifier:@"dataCell" forIndexPath:indexPath];
for (int i = 0; i <= [timeResultArray count]; i++)
{
cell.numberOfLesson.text = [NSString stringWithFormat:@"%d", i];
}
return cell;
}
但我发现这是错误的,我对另一种解决方案感到困惑。你能给我一些建议吗?
最佳答案
cellForRowAtIndexPath
为每一行调用。不需要循环。只是做:
- (DataManageTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *objectDate = [timeResultArray objectAtIndex:indexPath.row];
DataManageTableViewCell *cell = [timeOfScheduleTableView dequeueReusableCellWithIdentifier:@"dataCell" forIndexPath:indexPath];
cell.numberOfLesson.text = [NSString stringWithFormat:@"%lu", (unsigned long)indexPath.row];
return cell;
}
请注意,您没有使用 objectDate
。应该如何使用?
关于ios - 枚举 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27366468/