简体   繁体   English

如何快速冻结tableView单元格?

[英]How to freeze a tableView cell in swift?

I want to freeze a tableView cell on top of screen, so that while scrolling, other cells move but the top cell stays on its place. 我想在屏幕顶部冻结一个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

Thank you. 谢谢。

try this: 尝试这个:

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
}

Use these methods to create tableview header and add any subviews in it. 使用这些方法创建tableview标头,并在其中添加任何子视图。

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM