将两个 XIB 连接到一个 ViewController [英] Connect Two XIBs To One ViewController
问题描述
从根本上说,我想要一个适用于 iPhone 的视图,以及一个适用于 iPad 的视图.但是,我想对它们使用相同的视图控制器,因为它们是相同的东西,只是针对每个设备进行了优化.
I am, in all basics, wanting to have a view for iPhones, and one for iPads. However, I want to use the same view controllers for both of them, since they are the same thing, just optimized for each device.
我知道这样做是可能的,因为它是一个通用应用程序,通用项目的默认视图包括一个用于 iPhone 的主视图和一个用于 iPad 的主视图.但是,它们是自动实现的,所以我不知道如何复制它.
I know it's possible to do this, because it is a universal app and the default views for a universal project include one main view for iPhones, and one main view for iPads. However, they're implemented automatically and so I don't know how to replicate this.
所以,这个问题的要点是:如何将两个 xib 连接到一个视图控制器?
So, the jist of this question is: How do you have two xibs connected to one viewcontroller?
谢谢,
- 杰克
推荐答案
在代码中..无论你在哪里看到新视图..这样做
in code.. wherever you lot the new view ..do like this
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
self.MainView = [[[YOurViewController alloc] initWithNibName:@"YOurViewController_iPad" bundle:nil]autorelease];
}
else
{
self.MainView = [[[YOurViewController alloc] initWithNibName:@"YOurViewController_iPhone" bundle:nil]autorelease];
}
您必须用您的笔尖名称和类名称替换..
You will have to replace the nib name and class name with yours..
除此之外...一个更重要的步骤是进入每个xib文件..点击文件所有者..然后进入i*dentity inspector*(右上角的图标).. 确保它属于 YOurViewController 类
Above that...one more important step is to go in each xib file..click on File Owner.. and in the i*dentity inspector* (icons on the top right side) .. make sure it is of class YOurViewController
这篇关于将两个 XIB 连接到一个 ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!