开发者

correct indexPath.row selection in TableView which has multiple sections?

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 ind开发者_如何学JAVAexPath.row ?any tutorial?


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;


UITableview sends the delegate a

willSelectRowAtIndexPath: and didSelectRowAtIndexPath: message

and it send a

UITableViewSelectionDidChangeNotification notifications to observers.

By listening to these messages your will know what rows are selected.

There is a template in xCode with a UITableView which is a good starting point for learning UITableView. Your could implement it around an NSArray of strings as your datasource. That way focusing your learning effort on the UITableView code.

Best way is really to make a simple UITableView and flesh out the delegate methods along with the any calls to observers step by step.

Apples class reference will get you a long way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜