简体   繁体   中英

UITableView won't show floating section title

In my app I'm having some weird issues with UITableView . Basically my tableview is made of two sections with 10 rows each. I can't get it to show floating section headers with section titles (like "Music" app showing a section for each letter of the alphabet for example). I populated the tableView with some all-the-same cells for testing it but the table view won't show floating section headers, the only thing where I can see section titles (by the way "Anno 1" and "Anno 2" are the titles I need to show) is the bar on the right (is there anyway to hide this index bar?).

Can anybody help me in getting the tableview to show the section titles? Shouldn't it show them automatically or is there any property I must set in order to get them?

Is your table style "plain"? The headers don't float on style "grouped". Just a guess.

Also wondering if you are using custom section header views or just setting the section title.

I just solved the problem! I was messing pretty badly with datasource methods. Basically the problem was that I thought that the method to set the section titles was:

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

This methods instead refers to the right bar for fast scrolling! The right method to use for setting the titles of the sections is this one:

  • (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

here you return the title for the particular section passed as parameter.

Moreover if you don't override the first method I listed, the tableview won't show the bar for fast scrolling which in situations like the one I'm dealing with may be useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM