Saturday, November 19, 2016

Swift 3 hiding UITableView empty cells

What if our table view is having less number of cells than it's visible area. The remaining empty cells looks very odd. It's always good to hide the empty cells in a table. As an example see how the table is looking If the number of participants are only 3 as shown below.



We can remove these empty cell by giving an empty view as the footer view of the table.
Give it in the viewWillAppear override method of view controller.



    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        self.tableViewRank.tableFooterView = UIView(frame: CGRect.zero)

    }


Now, see the result.




Hope this post is useful. Feel free to comment incase of any queries.