UITableViewController truncating section header title
I've got an iPad app with a UITableViewController. I am setting the header titles for my table sections using
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
When the table loads, if I scrol开发者_如何学运维l down too quickly, when a section header appears on screen it will be truncated to the first letter and ... (ie "Holidays" is trucated to "H..."). If I keep scrolling down until the header goes off the top of the view and then scroll back up to it, the title appears correctly in full.
Has anyone ever experienced this?
Be sure that you're returning nil
in titleForHeaderInSection
for sections where you don't want a title, instead of @""
.
For whatever reason the iPad is using the length of the empty string for the headers text length while scrolling, and then doesn't redraw the header (while on iPhone it does). Returning nil
for sections where you don't want a header produces the desired behavior on both iPhone and iPad.
e.g., the code below draws the header titles correctly:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case NUM_SECTIONS-2:
return @"Second to last";
break;
case NUM_SECTIONS-1:
return @"last";
break;
default:
return nil;
break;
}
}
while the code below shows "..." when scrolling quickly past the headers:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case NUM_SECTIONS-2:
return @"Second to last";
break;
case NUM_SECTIONS-1:
return @"last";
break;
default:
return @"";
break;
}
}
精彩评论