Reputation: 9979
What would be best way to create a pagination engine architecture ?
In my previous implementation I'd
- UIViewController
- property UITableView
- with two sections in tableView. One for normal display and other
- for PaginationCell
- and rest of the business logic how to enable and hide indicator View
We thought this is a too much of duplicate code for every feature and decided to remove duplicate code.
And we wrote a category on UIViewController
to handle data pagination. Now we handle all calculation inside the category using scrollViewDidScroll
and add indicator footer view using objc_setAssociatedObject
.
I believe Associated objects
should be seen as a method of last resort, rather than a solution in search of a problem (and really, categories themselves really shouldn’t be at the top of the toolchain to begin with).
So my question is that - Is this new design a best solution for the problem. Or would you recommend some better approach ?
Upvotes: 0
Views: 118
Reputation: 17707
I don't get exactly what is the duplicated code you don't want, but I don't think at all that using a category is a good approach for this problem.
What I can suggest is to have a good architecture with separated responsibilities. This will lead you to the solution.
If can help you can read my article Anatomy of a TableView(Controller) Architecture and the one specific on Interaction Objects. You can imagine Interaction Objects like boxes with all the information the cell needs, like:
In general, following the approach described you should not feel stuck in front the most of the situations.
;)
For pagination, I would create a manager which is a dependence of the table view controller. The idea is:
Upvotes: 1