【问题标题】:Return cells with different cell identifiers返回具有不同单元标识符的单元
【发布时间】:2015-02-26 20:45:10
【问题描述】:

我有一个包含多个单元格标识符的自定义单元格。我尝试了以下代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    NSString *cellID;
    switch ([indexPath section]) {
        case 0:
            cellID = @"firstCell";
            break;
        case 1:
            cellID = @"secondCell";
            break;

        default:
            break;
    }

    customCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];

    return cell;
 }

当我运行应用程序时,它会显示第一个单元格 2 次,即使在情节提要中,有 2 个单元格里面有不同的对象。

【问题讨论】:

    标签: ios objective-c uitableview custom-cell


    【解决方案1】:

    [indexPath section] 真的是你想要的吗? 我想你想要[indexPath row]

    【讨论】:

      猜你喜欢
      • 2019-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-02
      • 1970-01-01
      • 2013-10-05
      • 2019-02-19
      相关资源
      最近更新 更多