简体   繁体   中英

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.

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.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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