开发者

How to change dynamically the xib of a UIVIewController

I have an UIVIewController "controller1" for instance. This controller is instanciated with initWithN开发者_运维问答ibName... with "file1.xib". I want to dynamically change the xib file of my "controller1" to "file2.xib"

To resume :

"controller1" <-> "file1.xib" and I want to dynamically have : "controler1" <-> "file2.xib"

How can I do this ?

Hope I was clear.


When you want to change views in a UIViewController just just use this code:

NSArray *nibObjs = [[NSBundle mainBundle] loadNibNamed:@"file2" owner:self options:nil];
UIView *aView = [nibObjs objectAtIndex:0];
self.view = aView;


I have two responses :

1) Why - this isn't something that you would normally do - what makes this case special? In fact, I'm going to edit this to be more emphatic --> DON'T DO IT <-- there will be all sorts of dependencies in UIViewController that you don't know about (for example if there is a low memory warning and your view controller unloads it's view, which xib would it load the view from when it had to display it again?)

2) If you desperately had to you can remove the view and reload it though NSBundle's loadNibNamed:owner: passing in the new xib and self as the owner.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜