This should be a pretty basic question, I’ll be happy even if you can link to some sort of article/tutorial that covers this (or a similar) subject.
I have an application with four tabs, each tab containing a navigation controller with a table view. I am not using UITableViewController subclasses, as I want to have a static view on top of some tables and an image background below everything. I am also using different types of custom cells (mostly configured with images and code in -willDisplayCell). As I want the same look and feel for all my tables, I am wondering how could I reuse some code, but I’m having trouble to figure this out. Do I have to create a “base” UIViewController subclass with a UITableView outlet, and then use this one as my superclass? Or do I have to just implement my UITableViewDelegate in a separate class and use an object of that class as the table view delegate? Or should I use a custom UITableView and subclass that one instead?
I could give more details if needed, but I suppose this is enough for a starting discussion. Thanks for any help!
I would consider subclassing UITableView and setting the
dataSourceanddelegateto self and implement GUI logic inside the class and create a custom logic for getting your data in and out (probably forwarding some dataSource/control delegate functions to one of your VCs).The layouting code for cells should really be placed inside cell logic! You should consider creating custom
UITableViewCellsubclasses (and maybe XIBs for them) that contain logic for layouting & reusing. (Maybe adataObjectproperty that makes the cell read your model?!). You can then use your UITableView subclass to create and manage those cells (e.g. a mapping between model classes and XIB names)This is probably a way to generate a lot of reusable code where you just need to change details like adding model classes or modifying their layouting, or subclassing model classes or subclassed UITableViewCells.