I have some initialisation code in the
viewWillAppear: methods that is used across a number of my UIViewController subclasses (which implement < UITableViewDataSource, UITableViewDelegate>):
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
self.tableView.frame = self.view.bounds
My thinking is to subclass UIViewController and include these methods in the subclass so as not to have to write this code in all my view controllers.
What are your thoughts on this? I'm wondering if this might give rise to issues retaining the tableView.
Have you considered this structure:
UIViewController -> your_First_Level_Subclass_View_Controller -> your_Second_Level_Subclass_View_Controller
In the 1st level, you implement those reusable/tableView-related codes, but you don't actually use this 1st level controller. You then subclass this 1st level to create your 2nd level controllers, which are the ultimate controller that you are gonna use.