So I have an extensive hierarchy of UITableViewControllers that I need to navigate through. Each one is going to need it’s own Custom View Controller. My data-source for any particular tableview is currently an array of strings, like “A,B,C,D,E,F”. My didSelectRowAtIndexPath method is a long list of if statements, like this (pseudocode):
if cell.text = "A"
alloc init AViewController
navigationController push aViewController
if cell.text = "B"
alloc init BViewController
navigationController push bViewController
I think this is messy. There has got to be a cleaner way to do this. Any “best practices” for this? My best idea is to make a custom class that contains a cellTitle and a viewController Class. Then I can use an array of those as my datasource, and do this kind of thing:
UITableViewController *newView = [custom.viewControllerClass alloc] init...
Thoughts?
Add a property on your top-level table view controller:
In
viewDidLoador other initialization method:In
didSelectRowAtIndexPath: