Reputation: 3456
I am using ECSlidingViewController, a library that gives a side-drawer effect. My application opens to a (navigation controller holding a) table view controller of 'Nearby' results, and the cells segue to a scroll view controller.
The hidden left menu is a table view controller (of different class) with a few options, 2 of which are other table view controllers that will use the same layout, cell prototypes, and detail scroll view as the table view seen on startup.
I would like to know if it would be better design to make a more generic tableView with some sort of property like an enum'd typeOfDisplay, which lets me conditionally manage different nuances like populating cells from server/CoreData, navbar titles, sort order, toggling auto-updating, editability, etc. - OR - if I should make a NavigationController->TableViewController->ScrollViewController for each different view controller (A 'Nearby', 'Featured', and 'Saved')
I'd like to reuse my table view because the cells/display/detail will be identical, but the methods for populating the table are different, and I don't want to make something that's difficult to modify.
Edits -
If you are familiar with table views inside tab-bar contollers, the implementation details should be nearly the same.
Upvotes: 0
Views: 910
Reputation: 2567
It's better to put view configuration into view controller. But there can be ways to reuse the configuration actions.
I have ran into the same situation like yours. And I decided to use Strategy Pattern to refactor my controllers. I put all the data related stuff into a TableDataManager
class which conforms to the UITableViewDataSource
and UITableViewDelegate
protocols and I applied polymorphism to it to configure the data in cells and the appearance of the UITableView
under different circumstances at runtime.
All the identical actions are implemented in TableDataManager
, and nuances are overridden by subclasses of TableDataManager
. By assigning a proper subclass of TableDataManager
to a view controller, there is no need for you to copy and paste the identical cells/display/detail actions here and there.
That's my experiences. Hope it will help.
Upvotes: 3
Reputation: 6510
I would recommend you to use different view controllers for different datasources. It sounds good initially to put them all together in one place, but as time goes by, you may need to add different functionalities to each table view, and your view controller will be a horrible mess.
Upvotes: -1