I have an array which contains 2 types of items (lets call them type a and type b) which are to be displayed in a table view.
The table view can be filtered such that either just items of type a are displayed, or just items of type b, or all items are displayed and the user can control which filtering is applied by hitting one of 3 corresponding tabs.
So this suggests that my app’s root controller should be a tab bar controller.
If that were the only requirement then I would make the tab bar controller have 3 table view controllers, however there is another requirement that I don’t know how to design it in a clean way:
If there are no items to be displayed for any of the filters then instead of an empty table view there should be displayed an image and some text (the image and text is different depending upon which filter is selected). So maybe this could have been achieved by setting background images for the table view BUT if filter a is applied then in addition to the images/text a button should also be displayed – which I am assuming cannot be set as the background to a table view. Hence implying that I need a set of separate view controllers to handle displaying the image/text/button views.
I suppose I could have the tab bar controller dynamically swap in and out these view controllers with the table view controllers depending upon if there are items to display for each filter or not, but this seems messy.
So then I was thinking maybe the tab bar controller should own 3 navigation controllers, and each navigation controller has as its root view controller a controller to display the image/text/button if there are no items, otherwise it would push a table view controller onto its stack (and pop it off if the number of items goes down to 0).
Is this a valid option? Is there a canonical pattern for my described behaviour?
TIA
This is actually fairly easy. Use a
UITabBarControlleras your main interface. The view controller for each tab will be a subclass ofUIViewControllerwith aUITableView. Each table view controller will load the data appropriate for the its tab. If each tab behaves the same (other than the filter) then this works great as your logic will be in one controller implementation. If you need different behavior per tab, no big deal, customize as needed.