I have question : I created table with multiple sections (they are set from webService response, so they are dynamic). For example, first section have 3 cells (0,1,2), second section - 4 cells (0,1,2,3), third section - 7 cells (0,1,2,3,4,5,6).
When I click, for example, on third cell in third section, I can only get a number in which this cell is (third section), and a number of cell IN CURRENT SECTION (third cell). But I would like to know, no matter which section, what is the cell's number (so, in the above example - third cell in third section, it would be tenth cell)
What to do? how to get that number?
for example in tableView:cellForRowAtIndexPath:
if you want to use it in the cell as text.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//....
NSInteger sum = 0;
for(NSInteger idx = 0; idx < indexPath.section, ++idx){
sum += [tableView tableView:tableView numberOfRowsInSection:idx];
}
sum += indexPath.row +1;
//....
}
but also tableView:didSelectRowAtIndexPath:
would work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.