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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With