I am having a view to display a list of Shops within a UITableView.
The user should have the possibility to modify the shops displayed by some filters.
For example it should be possible to display the shops ordered by name (with the first letter as section header). Further the user should be able to display just the favourites or sort the shops by category (category name is section header):
I did not want one table view, handling all the filters because I thought it would be a mess of if-then-else tags depending on the current filter. So I decided to create 4
UITableViewControllers with each of them handling one filter.
That’s exactly what I need, no redundancy so far, because the tableVC delegate and datasource methods are the ones which need to be implemented differently.
But now I do need a header which appears depending on the scroll position of the table. This is exactly the same in all of the 4 tables. But how should I solve this issue now?
Implement the UIScrollViewDelegate methods in each of the four UITableViewControllers redundant? Create a ParentViewController handling the scrollView methods (which would not be so easy because of the table datasource and delegate methods…
Any suggestions how to solve this properly? How would you do this?
I would appreciate any help, thanks in advance.
I would create a parent class, taking care of the header and derive the UITableViewControllers for the filters from it.
The superclass takes care of the common elements (like the header), the subclasses take care of the actual display.
Alternatively, you can create an overloaded method, which returns an Array of cells to display.
Store this array and when the delegate (in the superclass) asks for the ‘cell data’, give him the corresponding element in the array.