UITableView 部分标题与自定义 headerView 重叠?

Yan*_* Li 3 objective-c uitableview ios

我试图调整视图大小或添加约束但不起作用。 在此处输入图片说明

在此处输入图片说明

这是代码不起作用:

- (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;
    }

}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试这个时,它可以找到。(这不是我想要的,我想在故事板中添加标题视图但不以编程方式添加它。)

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];
Run Code Online (Sandbox Code Playgroud)

Ada*_*aka 5

设置您在 tableView viewForHeaderInSection 中创建的视图的 zPosition

快速版本:

sectionView.layer.zPosition = -1
Run Code Online (Sandbox Code Playgroud)