选择 iPad 和 iPhone 的启动视图
我的第一个应用程序仅适用于 iPhone,我决定也实现在 iPad 上使用的功能,并且我想要选择的第一件事是在打开 iPhone 或 iPad 时选择要使用的视图,在我的代表中写道:
NSString *devy = [[UIDevice currentDevice]model];
if ([devy isEqualToString:@"iPad"]) {
[window addSubview:viewController.viewCpuIpad];
[window makeKeyAndVisible];
} else {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
当 iPhone 时没问题,但当我在 iPad 上打开它时仅显示空白屏幕....哪里出了问题?
谢谢
my first application that was just for the iPhone I decided to also implement the ability to be used on the iPad and the first thing I wanted to choose the view to use if it were in the opening of an iPhone or iPad, in my delegate I wrote :
NSString *devy = [[UIDevice currentDevice]model];
if ([devy isEqualToString:@"iPad"]) {
[window addSubview:viewController.viewCpuIpad];
[window makeKeyAndVisible];
} else {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
When the iPhone's okay, but when I open it on the iPad only displays a blank screen .... where wrong?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apple推荐的方式(取自Xcode的通用应用程序项目模板)是:
如果您不想使用IB,您可以在视图控制器的loadView方法中创建视图,例如:
(UI_USER_INTERFACE_IDIOM()是支持iOS 3.1及更早版本的宏。 )
Apple's recommended way (taken from Xcode's universal application project template) is:
If you don't want to use IB, you can create your view in view controller's loadView method like:
(UI_USER_INTERFACE_IDIOM() is a macro to support iOS 3.1 and earlier.)
当您在 iPad 中启动时,不要调用
[window addSubview:viewController.viewCpuIpad];
尝试
viewController.view = viewCpuIPad;
[window addSubview: viewController.view];
我的建议是,当您在 iPad 上启动时,不要更新 viewController.view 属性。
默认情况下,当您创建 nib 时,viewController.view 设置为为 iPhone 显示的 nib 视图。
对于 iPad,您应该将此 [viewcontroller view] 属性更新为您指定的视图。另外,正如 Hoshi 所建议的,拥有两个不同的 Nib 文件也是一个好方法,以便您可以根据条件加载所需的 nib。
希望这有帮助:)
When you are launching in iPad, instead of calling,
[window addSubview:viewController.viewCpuIpad];
try like,
viewController.view = viewCpuIPad;
[window addSubview:viewController.view];
My suggestion is, you are not updating the viewController.view property when you are launching on iPad.
By Default, when you created the nib, the viewController.view is set to nib view which is displayed for iPhone.
For iPad, you are supposed to update this [viewcontroller view] property to your designated view. Else, as suggested by Hoshi, its also a good way to have two different Nib files so that you can load the required nib based on the condition.
Hopes this helps :)