开发者

When should I set a custom class override default UIViewController for a xib file?

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 us开发者_开发问答e 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.


As far as the xib file goes, I think you are talking about the class identifier for the file's owner? That only needs to be your custom subclass if you have specific actions or outlets that you are connecting in interface builder that only exist in your subclass.

If there are no subclass specific features you are using in the xib, the you can use UIViewController instead. This would allow you to reuse the same xib file for several different view controller subclasses if you liked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜