如何冻结 swift 中的 tableView 单元格?

How to freeze a tableView cell in swift?

我想冻结屏幕顶部的 tableView 单元格,以便在滚动时其他单元格移动但顶部单元格保持原位。

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)
        cell. //I think it must be here
        return cell

谢谢。

使用这些方法创建表视图header并在其中添加任何子视图。

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 50
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let header = UIView.init()
    header.backgroundColor = UIColor.gray
    //Add subviews here
    return header
}

试试这个:

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 65
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let header = view as! UITableViewHeaderFooterView
    header.textLabel?.textColor = UIColor.black
header.textLabel?.text="adadafaf"//ur data
}