2

I have an UIVIewController "controller1" for instance. This controller is instanciated with initWithNibName... 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.

4

2 回答 2

8

当您想更改 UIViewController 中的视图时,只需使用以下代码:

NSArray *nibObjs = [[NSBundle mainBundle] loadNibNamed:@"file2" owner:self options:nil];
UIView *aView = [nibObjs objectAtIndex:0];
self.view = aView;
于 2010-12-21T11:45:33.753 回答
1

我有两个回应:

1) 为什么——这不是你通常会做的事情——是什么让这种情况变得特别?实际上,我将对其进行编辑以更加强调->要这样做<-在 UIViewController 中将存在您不知道的各种依赖项(例如,如果内存不足警告并且您的视图控制器卸载它的视图,当它必须再次显示它时它会从哪个 xib 加载视图?)

2)如果你迫切需要你可以删除视图并通过NSBundle 的 loadNibNamed:owner:将新的 xib 和 self 作为所有者传递给它。

于 2010-12-21T11:45:13.703 回答