Show custom label when no data available for tableView

后端 未结 2 1172
花落未央
花落未央 2021-02-14 18:21

The app in question has an ability for users to mark items as favourite. When the user has no favourites saved, I\'d like to notify them of the fact (mostly I hate the idea of

2条回答
  •  一生所求
    2021-02-14 18:55

    What I personally would do is the following. As you said yourself, in the method numberOfRowsInSection you should check the count of your tableView datasource, if its 0 you should return 1 in order to display the 1 cell ou want.

    Then in cellForRowAtIndexPath you should check the count again, if it returns 0 you know that the table view is trying to draw your "You currently have no favorites" and you can set the text.

提交回复
热议问题