如何在 iOS 中调用不同的 Storyboard? [英] How to call different Storyboards in iOS?
本文介绍了如何在 iOS 中调用不同的 Storyboard?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用两个故事板,第一个用于 iphone Main.storyboard
,第二个是 Main_iPad.storyboard
,我想分别为 iPad 和 iPhone 调用我正在使用这个代码:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];EABaseRootVC *loginController = [storyboard instantiateViewControllerWithIdentifier:@"root2"];UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginController];self.window.rootViewController=navController;}别的{UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];EABaseRootVC *loginController = [storyboard instantiateViewControllerWithIdentifier:@"root"];UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginController];self.window.rootViewController=navController;}
但它总是显示 Main.storyboard 的 iPhone 资产.
我已经在关注这个
I am using two storyboard first one for iphone Main.storyboard
and second one is Main_iPad.storyboard
and i wants to call separately for iPad and iPhone i am using this code:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
EABaseRootVC *loginController = [storyboard instantiateViewControllerWithIdentifier:@"root2"];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginController];
self.window.rootViewController=navController;
}
else
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
EABaseRootVC *loginController = [storyboard instantiateViewControllerWithIdentifier:@"root"];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginController];
self.window.rootViewController=navController;
}
But its always shows iPhone assets for Main.storyboard.
i am already follow this Different storyboards for iPhone and iPad in xcode 6
if you have any other idea so please suggest me. what i am doing wrong?
解决方案
To identify Apple devices specifically whether it is iPhone
or iPad
use below code:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
// code for iPad
}else{
// code for iPhone
}
And must add these two keys inside your project's .plist
file.
Main storyboard file base name (iPad)
Main storyboard file base name (iPhone)
See image:
这篇关于如何在 iOS 中调用不同的 Storyboard?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文