2011-12-07 34 views
2

我正在使用靜態分組的UITableView向用戶顯示一些設置。每個組上面都有一個標題。從靜態表格視圖獲取標題標題

我想定製表視圖的外觀,我想在整個應用程序中使用這個外觀。因此,我已經繼承了UITableViewController,並且我的TableViewControllers繼承自我的子類。

有沒有一種方法可以使用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; 
}