旋转时在当前视图上加载不同的 XIB
我的应用程序有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是通过导航控制器实现此功能的一个很好的示例:
支持多个方向的最简单方法?当应用程序处于横向模式时,如何加载自定义 NIB?
Here's a nice example of implementing this via a navigation controller:
Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?