When should I set a custom class to override default UIViewController
for a xib file?
For example, I have a UIViewController
subclass named SettingViewController
, and a xib file namedSettingViewDetail.xib
.
I found whether I set a custom class for the xib or not(default is UIViewController
), my following code will work normal, it will create a controller for me
SettingViewController *oneView = [[SettingViewController alloc] initWithNibName: @"SettingViewDetail" bundle:nil];
and I can use it to control view navigation:
[[[[UIApplication sharedApplication] delegate ] naviController] pushViewController: oneView animated:TRUE];
I want to know when should I set a custom class for xib, and what reason for this?
If you want to set outlets (references to your subviews in this .xib) and have simple (without using tags) access to that subviews in your SettingViewController
then you should set appropriate class of File's Owner
and then that IBOutlet
's will appear.
In similar way you can easily set methods (IBAction
's) that will be called when user click the button, for example.
So, in the general case, you can just reduce amount of your code.