如何在iOS中调用不同的故事板?

时间:2016-09-20 12:30:09

标签: ios objective-c storyboard

我正在使用两个故事板,第一个用于iphone Main_iPad.storyboard,第二个用于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; } ,我想分别为iPad和iPhone调用我正在使用此代码:

var mvcContext = context.Resource as 
    Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext;

if (mvcContext != null)
{
    // Examine MVC specific things like routing data.
}

但它总是显示Main.storyboard的iPhone资产。

我已经关注此Different storyboards for iPhone and iPad in xcode 6

如果您有任何其他想法,请建议我。 我做错了什么?

1 个答案:

答案 0 :(得分:0)

要明确识别Apple设备是iPhone还是iPad,请使用以下代码:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
    // code for iPad
}else{
    // code for iPhone
}

并且必须在项目的.plist文件中添加这两个键。

Main storyboard file base name (iPad)
Main storyboard file base name (iPhone)

见图:

enter image description here