You should look into Method Swizzling. It helps you change the functions/function bodies at run time.
There is a great tutorial here.
The whole pose / swizzle approach is really useful if you want to tamper with the OS / private SDK supplied classes - but you generally shouldn't be doing that and it's not a good idea to use it as a standard approach in your own code.
The scenario: Defining class of controller at run time
You would usually do this by using an abstract superclass / interface / @protocol to define the interface that your potential controllers need to implement and then switching them in and out at runtime.
In your case it seems that you would have one controller which acts as a proxy for the true controller. You also don't technically need an @protocol because UITableViewController
is effectively your abstract superclass, but it would be best for your proxy to be a UITableViewController
and own the view and for your other controllers to be NSObject
subclasses and simply conform to the UITableView DataSource/Delegate
protocols.