Handling an empty UITableView. Print a friendly message

前端 未结 22 1205
青春惊慌失措
青春惊慌失措 2020-12-04 05:22

I have a UITableView that in some cases it is legal to be empty. So instead of showing the background image of the app, I would prefer to print a friendly message in the scr

22条回答
  •  青春惊慌失措
    2020-12-04 05:56

    Probably not the greatest solution, but I did this by just putting a label at the bottom of my table and if the rows = 0 then I assign it some text. Pretty easy, and achieves what you are trying to do with a few lines of code.

    I have two sections in my table (jobs and schools)

        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    
        if (jobs.count == 0 && schools.count == 0) {
            emptyLbl.text = "No jobs or schools"
        } else {
            emptyLbl.text = ""
        }
    

提交回复
热议问题