正确的TableView中的indexPath.row选择有多个部分? [英] correct indexPath.row selection in TableView which has multiple sections?
本文介绍了正确的TableView中的indexPath.row选择有多个部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有多个部分的tableview。每个部分都有不同的行数。
当我在特定部分选择特定行时,我如何才能找到正确的indexPath.row
?任何教程?
i am having tableview with multiple sections .each section is having different no of rows. when i select in particular row in particular section, how can i find correct indexPath.row ?any tutorial?
推荐答案
我不知道正确是什么意思。 indexPath.row
始终是该部分的本地,这意味着
I don't know what you mean by "correct". The indexPath.row
is always local to the section, which means
section 0
---------
[ row 0 ]
[ row 1 ]
[ row 2 ]
---------
section 1
---------
[ row 0 ]
[ row 1 ]
---------
section 2
---------
[ row 0 ]
[ row 1 ]
[ row 2 ]
[ row 3 ]
---------
要获得全局行,可以计算部分和。
To get the global row, you can compute a partial sum.
NSUInteger row = 0;
NSUInteger sect = indexPath.section;
for (NSUInteger i = 0; i < sect; ++ i)
row += [dataSource tableView:tableView numberOfRowsInSection:i];
row += indexPath.row;
return row;
这篇关于正确的TableView中的indexPath.row选择有多个部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文