gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:56:10 30 4
gpt4 key购买 nike

我试图调整 View 大小或添加约束但不起作用。 enter image description here

enter image description here

这是无效的代码:

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

}

但是当我尝试这个时,它找到了。(这不是我想要的,我想在 Storyboard 中添加标题 View 但不是以编程方式添加它。)

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];

最佳答案

设置你在tableView viewForHeaderInSection中创建的 View 的zPosition

快速版本:

sectionView.layer.zPosition = -1

关于ios - UITableView 部分标题与自定义的 headerView 重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36822758/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com