UITableViewController截断节标题标题

时间:2010-04-29 23:22:17

标签: uitableview ipad

我有一个带有UITableViewController的iPad应用程序。我正在使用

为我的表格部分设置标题标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

当表格加载时,如果我向下滚动得太快,当屏幕上出现一个部分标题时,它将被截断为第一个字母并且......(即“假期”被标记为“H ......”)。如果我继续向下滚动,直到标题从视图的顶部离开,然后向上滚动到它,标题将正确显示。

有没有人经历过这个?

1 个答案:

答案 0 :(得分:5)

请确保您在nil中为{strong>不想要标题而不是titleForHeaderInSection的部分返回@""

无论出于何种原因,iPad在滚动时使用空字符串的长度作为标题文本长度,然后不重绘标题(而在iPhone上则重绘)。对于您不想要标题的部分返回nil会在iPhone和iPad上产生所需的行为。

例如,下面的代码正确绘制标题标题:

- (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;
    }
}

而下面的代码在快速滚过标题时显示“...”:

- (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;
    }
}
相关问题