header通過下面兩個代理方法設置
- (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]; }