Reputation: 397
- (NSString*) tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
{
NSLog(@"%i",section);
}
If I scroll down the table I get the value of 0 2 3 4 ... If up 0 2 3 4 2 1 ... How to get the value without reduction or increase by 2?
Upvotes: 0
Views: 72
Reputation: 181
UITableView will call tableView:titleForHeaderInSection at its own discretion in order to get the title for a particular section when it needs it. It makes no promises about the order in which it will request the titles.
This should make no difference; it is up to you to know the title for a given section number regardless of the order, and return it from that delegate method when the table view asks for it. Try to read up on how UITableViews and their delegate/data source work together, and I bet you'll find that the thing you are trying to do is really easy.
EDIT: Now that you have clarified your goal slightly, I would suggest looking at the -indexPathsForVisibleRows method in UITableView. This will give you the NSIndexPaths that are currently visible in the table view, and you can find the index path with the smallest section value to determine the first section that is still visible/invisible in the table.
Upvotes: 1
Reputation: 1413
That method should just return the title for a specific section, regardless the order of the section index values.
The tableview will manage the section headers by itself, and just asks the datasource when it needs info. The datasource should know how to map the section index with the desired title.
Upvotes: 0