How to call different Storyboards in iOS?

元气小坏坏 提交于 2019-12-13 07:08:08

问题


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?


回答1:


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:



来源:https://stackoverflow.com/questions/39594149/how-to-call-different-storyboards-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!