开发者

Handling an empty Table view

What I am trying to do is pretty simple, I just want to display some message to the user that there are no entries in this table, rather than just displaying a blank page. An ideal example is in the app 开发者_StackOverflow社区store, if you search for something, but get no results, it just displays in the middle of the page "No Matches".

I've looked at a few solutions, and decided that the one i like best is here But theres a few little problems with it:

1) I can still drag around the image as if it was just a very large cell in the tableview

2) when I try to re-add the tableview to the tabelviewcontroller's view, I seem to get some kind of infinite recursion that eventually crashes

Anyone know a simpler way to do this? Or how I can resolve my current issues?


Don't remove the tableView, just add an UIView with your message (i.e. UIImageView) on top off it. It only needs to be big enough to cover the tableView. Place something like at the appropriate place in your UITableViewController:

if (results == 0) {
     [self.view addSubview:noResultsView];
}


Dan F it's very easy all you need to do is the following:

  • if there is no data in your source, add one object like No Data Found
  • Set a flag like BOOL bNoDataFound = YES
  • in CellForRowAtIndexPath delegate check your flag is YES fill the only cell with your text that you set before
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜