How to change dynamically the xib of a UIVIewController

ぃ、小莉子 提交于 2019-12-06 05:54:28

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!