Fixed header to UITableview?

前端 未结 5 804
日久生厌
日久生厌 2020-12-01 09:46

I\'ve got a UITableView that I\'d like to stick a 44px subview on top of. I tried tableViewHeader, but that scrolls with the rest of the table.

5条回答
  •  孤街浪徒
    2020-12-01 10:08

    Replace the TableViewController with a ViewController, inside it add a UIView with fixed height to place the fixed content you need, and below that add a UITableView.

    Create an outlet to your TableView

     @IBOutlet weak var tableView: UITableView!
    

    You can reuse all the funcs you already have removing the override word for example

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    
        let c = tableView.dequeueReusableCellWithIdentifier(cellId) as UITableViewCell!
        c.textLabel?.text = "A title"
        c.detailTextLabel?.text = "A subtitle"
        return c
    }
    

    See this answer to add the automatic refresh control if you need it Pull to refresh UITableView without UITableViewController

提交回复
热议问题