2

我在 UItableView 中有 6 个部分,每个部分显示 2 个单元格,通常,我希望它是这样的: 在此处输入图像描述

但是,这就是我所拥有的: http://i.imgur.com/iGoMpTK.png

每个 indexPath.row 在每个部分中都重复。这是代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"avenir";
    Avenir *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(!cell) {
        cell =[[Avenir alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
     cell.equipea.text=[arrayofClubA objectAtIndex:indexPath.section];

     cell.equipeb.text=[arrayofClubB objectAtIndex:indexPath.section ];


return cell;

}

从两个 NSMutableArray 中检索元素,一个用于单元格中的第一个左侧元素,另一个用于右侧元素单元格。怎么了?

感谢您的帮助。

4

2 回答 2

3

您需要从row和计算正确的索引column。由于每个部分有两对行,因此您需要乘以section2 和 add row,这将是零或一。最终结果应如下所示:

NSUinteger pos = indexPath.section*2 + indexPath.row;
cell.equipea.text=[arrayofClubA objectAtIndex:pos];
cell.equipeb.text=[arrayofClubB objectAtIndex:pos];
于 2013-05-07T17:54:04.313 回答
0

您总是为每个部分获取相同的文本,因为

cell.equipea.text=[arrayofClubA objectAtIndex:indexPath.section];

总是为每个部分返回相同的值(因为 indexPath.section 包含该部分的索引)。也许您想改为执行以下操作?

cell.equipea.text=[arrayofClubA objectAtIndex:indexPath.row];

此外,对于这些用途,使用免费的 Sensible TableView 框架可能更直接,因为它会自动处理显示您的数组。

于 2013-05-07T17:55:15.337 回答