How to freeze an uiltView cell in swift?

advertisements

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.


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
}