旋转时在当前视图上加载不同的 XIB

发布于 2024-12-01 02:43:03 字数 714 浏览 7 评论 0原文

我的应用程序有 2 个不同的视图(一个用于纵向,另一个用于横向模式),我想将它们分成不同的 XIB 文件,以便使用更少的内存。我已经这样做了,但是当更改 iPad 的方向时,我的视图变成空白。 我尝试执行以下操作:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
self = [[MyController alloc] initWithNibName:@"MyControllerLandscape" bundle:nil];
}

但它只是初始化没有数据的视图(没有图像,没有标签,...)。如何“卸载”当前视图并以界面方向“加载”新视图,避免弹出视图并推送新视图?

编辑:

我现在已经尝试过这个,它或多或少有效:

[[NSBundle mainBundle] loadNibNamed:@"myPortraitView" owner:self options:nil];
[[NSBundle mainBundle] loadNibNamed:@"myLandscapeView" owner:self options:nil];

我现在的问题是:如果我在 init 方法上执行此操作,它会将两个视图加载到内存中还是只是在需要时加载视图的引用?

I had on my application 2 different views (one for Portrait and another for Landscape mode) and I would like to separate them into different XIB files so that I'm using less memory. I've done so but when changing my iPad's orientation my view becomes blank.
I've tried to do the following:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
self = [[MyController alloc] initWithNibName:@"MyControllerLandscape" bundle:nil];
}

But it just initializes the view with no data (no images, no labels, ...). How can I "unload" the current view and "load" the new one with the interface orientation avoiding to pop the view and pushing a new one?

EDIT:

I've tried now this and it's more or less working:

[[NSBundle mainBundle] loadNibNamed:@"myPortraitView" owner:self options:nil];
[[NSBundle mainBundle] loadNibNamed:@"myLandscapeView" owner:self options:nil];

My question now is: if I do that on my init method, will it load both views into memory or just a reference to load the view when neded?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文