I have a program that creates UIViewControllers in a UISplitView depending upon which row is selected in a UITableView. For example, if the user clicks the row called ‘settings’, the program creates a view controller called settingsTableVC (which displays in the left-hand pane of the UISplitViewController) and a detail view controller called settingsDetailVC, which appears in the right hand pane.
The logic works fine, but I have a lot of code for each row in the initial tableView, for creating and setting up each ViewController, and their public properties and it seems to me a simpler way would be to define two generic ViewControllers, then cast them to the correct type in a method. That way, I can define their public properties generically (as they are all basically the same properties, pointers to the masterViewController and the tableViewController)
E.G.
UIViewController *leftController = nil;
UIViewController *rightController = nil;'
Then, in the didSelectRowAtIndexPath:
leftController = [[SettingTableViewController alloc]init];
rightController = [[SettingsDetailViewController alloc]init];
leftController.masterVC = self;
rightController.tableVC = leftController;
However, the complier warns – ‘UIViewController does not declare a property masterVC’.
How can I change the class of these ViewControllers at runtime?
You can do either of the following:
or
You have created your objects correctly, but as you assign them a
UIViewControllerpointer object type the compiler doesn’t know your objects are of your custom class.