【发布时间】:2014-02-25 10:55:25
【问题描述】:
我有一个包含多个部分的 UITableView。我没有使用每个部分使用一个数组的典型方法,而是使用一个数组。无论如何,我无法获取当前的 indexPath.row,就好像 tableview 中只有一个部分一样。
所以我想做的事情如下。如果section == 0,我只使用indexPath.row,但是如果section > 0,我想把上一个section的所有行加起来,得到当前section的当前行,得到总行数AS如果表格视图只有一个部分。
这是我当前的代码,但它无法正常工作,也许你们会看到我做错了什么。请告诉我:
if (indexPath.section == 0) {
currentRow = indexPath.row;
} else {
NSInteger sumSections = 0;
for (int i = 0; i < indexPath.section; i++) {
int rowsInSection = [activitiesTable numberOfRowsInSection:i] + 1;
sumSections += rowsInSection;
}
NSInteger row = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section].row + 1;
currentRow = sumSections + row;
}
【问题讨论】:
标签: ios arrays row nsindexpath uitableview