ios - 如何防止tableview section head在滚动时粘住?

标签 ios swift uitableview

我有一个包含许多部分的表格 View 。我正在使用一个实际的 tableview 单元格,我将其出队用作自定义节标题。我遇到的问题是当我将节标题“粘”到表格顶部直到出现下一个节时。

我怎样才能防止这种情况发生并让它像往常一样向上滚动?

这是我的代码

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    if section == 3 {
        let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell") as! HeaderTableViewCell
        return cell
    }
    return UIView()
}

最佳答案

执行以下步骤。

来自@IB

  1. 选择你的tableView
  2. 转到属性检查器
  3. 查找默认为 Plain 的样式属性下拉列表
  4. 将其更改为Grouped

或者,如果您以编程方式创建 TableView,请使用

let tableView = UITableView(frame: YourFrame, style: .Grouped)

关于ios - 如何防止tableview section head在滚动时粘住?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47359936/

相关文章:

ios - 解析 getDataInBackgroundWithBlock 未按顺序获取

ios - 初始化弱属性的惯用方法?

ios - 拖动时关闭键盘

ios - 使用 DocuSign iOS Native SDK 预填充自定义字段

iphone - 如何动态增加 UITableViewCell 的高度

ios - 当我在 UITableview 上滚动时,多个选定行的复选标记消失了。如何解决这个问题?

ios - Tesseract OCR 无法识别除法符号 "÷"

ios - 如何在 iOS 中使用 UIImagePickerController 从 photoGallery 获取视频?

ios - 展开 Segue 不起作用 SWIFT

ios - 使用 Storyboards 的具有不同单元格原型(prototype)和高度的 UITableView