UITableView tableFooterView shows at the top of the UITableView - wrong

前端 未结 7 2298
北海茫月
北海茫月 2021-02-08 15:37

I have created a very simple test case to reproduce this issue.

I am trying to set a footer view programmatically to a tableview. Please note that I am referring to the

7条回答
  •  隐瞒了意图╮
    2021-02-08 16:10

    I have tried the same with explicit frame values in swift and I achieved the behaviour as you asked for, Try it with the explicit frame value if you think its fine. And remove the layout constraints if its not needed.

       @IBOutlet weak var tableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        tableView.delegate = self
        tableView.dataSource = self
    
        let footerView = UIView(frame: CGRect.init(x: 0, y: 0, width: tableView.frame.width, height: 50))
        footerView.backgroundColor = UIColor.green
        tableView.tableFooterView = footerView
    }
    
    extension ViewController: UITableViewDelegate, UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        cell?.textLabel?.text = "\(indexPath.row)"
        return cell!
    }
    

    }

提交回复
热议问题