这是代码不起作用:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return 100;
}
return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//self.mainViewTableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0.1)];
if (section == 0) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 50, tableView.frame.size.width, 100)];
//[view setBackgroundColor:[UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1]];
[view setBackgroundColor:[UIColor redColor]];
[self.mainViewTableView setTableHeaderView:view];
return view;
}
else{
return nil;
}
}
但是当我尝试这个时,它可以找到。(这不是我想要的,我想在故事板中添加标题视图,但不能以编程方式添加它。)
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, 300)];
//[view setBackgroundColor:[UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1]];
[view setBackgroundColor:[UIColor redColor]];
[self.mainViewTableView setTableHeaderView:view];