从静态表视图中获取标题标题

时间:2011-12-07 19:56:23

标签: iphone static header uitableview subclass

我使用静态分组的UITableView向用户显示一些设置。在每组之上,我有一个带标题的标题。

我想自定义表视图的外观,我希望在整个应用程序中使用这种外观。因此,我已经将UITableViewController子类化,而我的TableViewControllers继承自我的子类。

有没有办法使用Interface Builder输入标题,在我的UITableViewController子类中更改标题的外观?

1 个答案:

答案 0 :(得分:1)

我尝试使用[self tableView:self.tableView titleForHeaderInSection:section]检索标题,但在发布此问题后我很快意识到它应该是从super调用的。因此:

[super tableView:self.tableView titleForHeaderInSection:section]

可以使用

自定义标题
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSString *title = [super tableView:self.tableView titleForHeaderInSection:section];

    if (title.length == 0) return nil;

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
    label.textColor = [UIColor whiteColor];
    label.backgroundColor = [UIColor clearColor];
    label.text = title;

    return label;
}