tags:

views:

36

answers:

1

Hi, I am implementing a table index view and amazed to see how my table indexes are working even without implementing:

 - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index method.

I have only implemented:

 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView 

Strangely, when I am running in breakpoints, Once i click on any of the index values my

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

method is getting called.

Any clue why this is so happening and what is the significance of sectionForSectionIndexTitle method then.

A: 

Any clue why this is so happening

Yes. When you tap (you do not click on an iPhone) on a table's index, the underlying table view will want to jump to that section, and the cells in that section. In order to do that, it has to ask the data source for those cells so it can render them on the screen.

what is the significance of sectionForSectionIndexTitle method then.

The documentation for tableView:sectionForSectionIndexTitle:atIndex: (which is an optional method in the UITableViewDataSource protocol) says:

Asks the data source to return the index of the section having the given title and section title index.

and

You implement this method only for table views with a section index list—which can only be table views created in the plain style (UITableViewStylePlain).

Does this apply for your UITableView? In other words, are you using a grouped table view style?

Shaggy Frog
I understood your first point but how come clicking on the index is taking me to the correct section. Yes, I am implementing UITableViewStylePlain.
Abhinav
You just asked me "why does tapping (NOT "clicking") on the index take the user to the correct section?"... *because that's what it's supposed to do*. (I don't think you meant to ask me that. Please rephrase.)
Shaggy Frog
You are right. I believe that this behaviour is implemented by tableView:sectionForSectionIndexTitle:atIndex: method which maps section indexes with actual sections. So how come without implementing this method and not letting the framework know which section index points to which section, I am getting the desired behaviour?
Abhinav