2012-04-21 52 views

回答

10

您可以通過實現方法tableView:viewForHeaderInSection:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 

    // create and return a custom UIView to use for the section here 

} 
+0

感謝您的回覆爲您的tableView的節頭的自定義視圖,我會嘗試。但是,我應該使用什麼尺寸或高度?我是否必須通過代碼創建它?我可以使用故事板嗎?謝謝! – Ricardo 2012-04-22 00:36:18

+1

我發現這個tableView:heightForHeaderInSection:非常感謝。 – Ricardo 2012-04-22 00:38:00

4
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 

NSString *sectionName = nil; 

switch (section) { 
    case 0: 
     sectionName = [NSString stringWithFormat:@"Header Text 1"]; 
     break; 
    case 1: 
     sectionName = [NSString stringWithFormat:@"Header Text 2"]; 
     break; 
    case 2: 
     sectionName = [NSString stringWithFormat:@"Header Text 3"]; 
     break; 
    } 

    UILabel *sectionHeader = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)] autorelease]; 
sectionHeader.backgroundColor = [UIColor clearColor]; 
sectionHeader.font = [UIFont boldSystemFontOfSize:18]; 
sectionHeader.textColor = [UIColor whiteColor]; 
    sectionHeader.text = sectionName; 

return sectionHeader; 

}

相關問題