Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is the point of tableView:sectionForSectionIndexTitle:atIndex:?

The documentation is not really clear about this. Why is the UITableViewDataSource asked to provide the section index for an index-bar section title?

I mean... what use cases make this method important? When is this called and why?

like image 995
dontWatchMyProfile Avatar asked Apr 12 '10 19:04

dontWatchMyProfile


2 Answers

Basically, it defines which section the table view scrolls to when you click on the specified section index title. Let's say you define your index titles as the letters A through Z, but you don't actually have items for each letter. In -tableView:sectionForIndexTitle:atIndex:, you would specify the next section that has an item.

like image 140
Jeff Kelley Avatar answered Nov 16 '22 23:11

Jeff Kelley


This website has a good answer :

sectionIndexTitlesForTableView: In order to properly render the index, the UITableView needs to know all index titles to display. This method returns an array of strings containing all indices. In our case, A, B, C, D, etc.

sectionForSectionIndexTitle: When you start scrolling through the index, the table needs to know how far down/up to scroll so that the letter you're touching corresponds the appropriate section in the table. This method returns an index value (integer) of the section you're currently touching in the index.

like image 25
Paul Avatar answered Nov 17 '22 00:11

Paul