UITableView的HeaderView和FooterView

header通过下面两个代理方法设置

 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

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

footer通过下面两个

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

 

如果要做整个tableview的header和footer,要通过tableview setHeaderView setFooterView

 

如果只是指定每个section的title,只需要tableView的dataSource的实现下面的方法来返回每个section的title

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

 

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

是用来自定义每个section的headView

 

 

如果是要自定义每个section的headView用第二个方法创建自定用的视图并返回。

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

if(section == 0) { CustomView *view = [[CustomeView alloc] init]; return [view autorelease]; }

posted @ 2013-07-11 10:05  子福当自强  阅读(11238)  评论(0编辑  收藏  举报
悟道