views:

364

answers:

3

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 scroll 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?

A: 

I'm having the same issue. Have you ever found a solution, or is this just a bug?

David
I showed it to an Apple engineer at WWDC. He confirmed it as a bug. I have submitted a bug report to Apple.
dl
+2  A: 

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;
    }
}
MikeV
Thanks so much for the workaround! What a bizarre little bug.
dl
A: 

Thanks, MikeV! This had be stumped. I noticed it was iPad only (3.2), not on iOS 4. I Googled the problem, came to here, and you nailed it!

I see that the docs do say, "If you return nil , the section will have no title." But they don't say how things go awry when you return an empty string.

Marc Rochkind