ios - 枚举 UITableViewCell

标签 ios objective-c uitableview

我有很多单元格,我想枚举它们。所以第一个单元格的标签为“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/

相关文章:

ios - 使用 Stackmob getLoggedInUserOnSuccess :^(NSDictionary *result) onFailure:^(Error *error) method

objective-c - 从 View 中获取按钮等对象。 iOS

iphone - 使用 initWithCoder 初始化 UITableViewCell 是否正确?

ios - 无法在 swift 3 中显示表格 View ?

iphone - xCode Organizer 中的分发证书

ios - 同步核心数据时,调用 URL ForUbiquityContainerIdentifier : needed?

iOS OpenCV haarcascade 用于其他面部情绪

ios - navigationItem.TitleView 不适用于 iOS 10

ios - 在 UISearchController 中搜索时无法在 tableView 中滚动

javascript - Vimeo 播放器 JS API 在 iOS 中无法运行