2011-12-07 13 views
2

スタティックグループ化されたUITableViewを使用してユーザーに設定を表示しています。各グループの上にはタイトルのヘッダーがあります。静的テーブルビューからヘッダータイトルを取得

私はテーブルビューの外観をカスタマイズしたいので、アプリケーション全体を通してこの外観を使用したいと思います。したがって、私はUITableViewControllerをサブクラス化し、私のTableViewControllerはサブクラスから継承しています。

Interface Builderを使用してヘッダーのタイトルを入力する方法はありますか?UITableViewControllerサブクラスでヘッダーの外観を変更しますか?

答えて

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; 
} 
関連する問題