I have a subclassed UITableView, ‘subclassChild’ which inherits from another subclass ‘subclassParent’. ‘subclassParent’ then inherits from UITableView.
My view controller inherits from a custom View Controller ‘GenericTableViewController’, and contains my UITableViewController which has the class of ‘subclassChild’.
‘GenericTableViewController’ customises my tables header and footers for all view controllers containing a table view.
My question is, how do I make it so that my UITableView can use ‘subclassChild’ and ‘subclassParent’ as its delegate and dataSource. Still making sure that ‘GenericTableViewController’ customises my tables header and footers.
Sorry if this is a bit confusing, I’ve tried to describe it as well as I can.
P.S I have added <UITabBarDelegate, UITableViewDataSource> in the header files.
And I have made sure that the table inherits from ‘subclassChild’ in IB.
Thanks in advance!
What you can do, is have your ‘GenericTableViewController’ have a delegate itself. It will do most of the work itself, but at the end it shall ask its delegate ‘anything else to do’?
And when the delegate says ‘Yes, there is something actually’, that code will get executed, serving as data source, delegate or whatever you want it to be. As an example (please forgive me for code inaccuracies):
This example assumes, that you have an array of tableview cells, but should give you a good idea. You don’t need to implement UITableViewDataSource to that subclass header files, but instead use a custom protocol.
Edit: Since apparently I was unclear in what I was aiming to do, allow me to add a little information.
The basic idea is to use ‘subclassChild’ and through it ‘subclassParent’ as delegates for GenericTableViewController, instead of using ‘subclassChild’ as the type for the tableView. (You should never subclass a view, unless you intend to change it’s drawing behaviour).
The general hierarchy would work like this:
subclassChild -> delegate -> GenericTableViewController <- DataSource/Delegate <- TableView
You’d need to create an init method, or a setter method, which sets this delegate, and a simple protocol, which allows you to call functions, like so:
In the .m file, this example would look like this:
This protocol/delegate ‘game’ can be expanded easily, giving you all levels of control you need…all the while with the GenericTableViewController as a ‘backup’, if any delegate isn’t set, or ‘not ready’ to answer the request for further instructions.
I hope this helps.