How do i set section titles to work with UITableViewStyleGrouped?
I set my tabe view to use UITableViewStyleGrouped in IB and the cells look fine, but the section headers still look like they are in UITableViewStylePlain. They are over on the 开发者_运维技巧left and position does not not match with cells and they do not scroll when I scroll the cells in the view.
I used
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
return [NSArray arrayWithObjects:@"Cats",@"Area",nil];}
to set section titles.
Cheers, Grant
Try implementing the - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section method of the UIDataSource protocol instead.
The sectionIndexTitlesForTableView:
is for the index on the right-hand side of your table.
Also, have you implemented - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section of the UITableViewDelegate ? If so, you may want to try without it.
According to the documentation for sectionIndexTitlesForTableView, it returns
An array of strings that serve as the title of sections in the table view and appear in the index list on the right side of the table view. The table view must be in the plain style (UITableViewStylePlain). For example, for an alphabetized list, you could return an array containing strings “A” through “Z”.
What you're looking for, I think, is tableView:titleForHeaderInSection:.
精彩评论