2013-04-30 163 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]; 
}