use*_*233 5 arrays row uitableview nsindexpath ios
我有一个包含多个部分的UITableView.我没有使用每个部分使用数组的典型方法,而是使用一个数组.无论如何,我无法获取当前的indexPath.row,就好像tableview中只有一个部分一样.
所以我想要做的几乎就是如下.如果section == 0,我只使用indexPath.row,但是如果section> 0,我想要添加上一节中的所有行并获取当前节中的当前行以获得总行号AS如果TABLEVIEW只有一个部分.
这是我目前的代码,它只是没有成功,也许你们会看到我做错了什么.请告诉我:
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;
}
Run Code Online (Sandbox Code Playgroud)
Chr*_*ian 11
首先你不需要第一个,因为它不会通过for-next.然后你添加一个不必要的,然后你可以像这样添加indexPath.row:
NSInteger sumSections = 0;
for (int i = 0; i < indexPath.section; i++) {
int rowsInSection = [activitiesTable numberOfRowsInSection:i];
sumSections += rowsInSection;
}
currentRow = sumSections + indexPath.row;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2839 次 |
| 最近记录: |