2013-04-30 160 views

回答

7

使用這些方法中,

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

上述用於設置視圖方法。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; 

以上設置標題的方法。 看到這一個,

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    UILabel *lbl = [[[UILabel alloc] init] autorelease]; 
    lbl.textAlignment = UITextAlignmentLeft; 
    [email protected]"LHR-SYD/372 Results"; 
    return lbl; 
} 

通過上述方法可以在不同的對象,你headerview補充。

(OR)

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ 
    return @"LHR-SYD/372 Results"; 
} 

這一個你的需求我想是這樣。

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ 
    return 30; 
} 

您可以使用此代碼

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

    UIView *transparentView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,10)]; 
    transparentView.backGroundColor=[UIColor clearColor]; 
    return transparentView; 

} 
+0

非常感謝各位的幫助 – user1448401 2013-05-01 10:25:24

1

這實際上是爲UITableView的默認標題設置標題視圖的高度。所有你需要做的是實現titleForHeaderInSection方法,它會出現。查看該方法的文檔,它有幫助很多

2

您可以更改默認的標題視圖BG:

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section { 
    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view; 
    header.backgroundView.backgroundColor = [header.backgroundView.backgroundColor colorWithAlphaComponent:1]; 
}