我正在尝试为分组的 UITableView 中的每个单元格创建索引计数,以便我可以将单元格值存储在数组中的正确位置,但我无法计算出它所需的数学:
索引运行如下,我的计数需要是:
indexPath.section = 0
indexPath.row = 0 cellIndex = 0
indexPath.row = 1 cellIndex = 1
indexPath.row = 2 cellIndex = 2
indexPath.row = 3 cellIndex = 3
indexPath.row = 4 cellIndex = 4
indexPath.section = 1
indexPath.row = 0 cellIndex = 5
indexPath.row = 1 cellIndex = 6
indexPath.row = 2 cellIndex = 7
indexPath.row = 3 cellIndex = 8
到目前为止,这是我的方程式,但它无法正常工作:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger cellIndex = numberOfSections * indexPath.section + indexPath.row;
}