iOS viewForHeaderInSection 覆盖其他单元格

标签 ios objective-c uitableview tableviewcell

我正在尝试在我的应用程序中实现标题 View ,并使用以下代码创建标题 View :

(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[[NSBundle mainBundle] loadNibNamed:@"FutureAppointmentsHeaderView" owner:self options:nil] lastObject];

    return view;
}

我还设置了headerView的高度如下:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 70;
}

当页面加载时,页眉 View 位于正确的位置(见第一张图片)。但是,当我滚动时,标题会覆盖其他单元格(请参见第二张图片。)

enter image description here

enter image description here

我不能因为我做错了什么而导致这种行为。非常感谢任何帮助。

最佳答案

这听起来不像是错误的行为。这就是 header 的行为方式。以 iPhone 上的通讯录应用程序为例 - 当您滚动时,带有当前字母的标题总是会对齐到顶部。当您继续滚动时,它会被一行中的下一个标题替换。

您应该做的是为页眉添加背景颜色,而不是让它保持透明。我认为一旦您这样做,一切都会看起来更好、更容易理解。

关于iOS viewForHeaderInSection 覆盖其他单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32205760/

相关文章:

ios - UIPickerView 宽度约束问题

objective-c - 在表格 View 单元格内的 UIImageView 中设置图像

ios - CoreData NSPredicate 按日期获取数据

ios - @escaping @callee_guaranteed (@guaranteed UIAlertAction) -> ()

ios - xcode 中的公制转换计算器

ios - 使用自定义单元格时,旋转会导致表格 View 超出安全区域

ios - 计算 UITableView 上选中的行数

关于 TableView 和构建自定义类模型的 iPhone MVC 问题

objective-c - 即时更改表格 View 行高

ios - willDisplayHeaderView 未在 TableViewController 中调用