An easy way to add empty views to your table view without subclassing anything
... a category that dynamically shows an empty view when there are no entries in your table view.
The empty view will be displayed whenever the table view has no cells in any section. Of course only if a view has been set via
nxEV_emptyView. Whenever the table view is reloaded or layouted the empty view gets updated.
The frame of the empty view is updated to the bounds of the table view, so make sure it layouts nicely for all the orientations and screen sizes (iPhone 5, yay) that you're targeting.
There might be scenarios in which you don't want the empty view to appear. For example when the content of the list has not yet been loaded and you don't want to scream at the user that there's none just because it has not yet been loaded.
In that case you can let your table view datasource implement the
UITableViewNXEmptyViewDataSourceprotocol and return
-tableViewShouldBypassNXEmptyView:. Whenever this value changes do a
-[UITableView reloadData]to update the empty view.
Add this to your Podfile
In your table view do:
nxEV_emptyViewproperty of the table view with the view you want to be displayed when the table is empty. You can use the Interface Builder to do so as well.
Contributions are highly welcomed!
Bonus points for feature branches :sunglasses:
This code is released under the 3-clause BSD License (aka new BSD License or modified BSD License). The full text is included in the LICENSE file in the root of the repository.