我决定为ios6和ios7使用不同的故事板,因此我需要在代码中实例化故事板。我在app delegate的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
但没有任何反应,它总是只是在iPad模拟器上运行时实例化名为iPadStoryboard
的故事板,我已经从info.plist中删除了主界面。有什么想法在这里发生吗?
- (void)loadStoryboards
{
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
UIStoryboard *mainStoryboard = nil;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
NSLog(@"1");
if (iOSDeviceScreenSize.height == 480)
{
mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone-ios5" bundle:nil];
} else {
NSLog(@"loading iPad storyboard");
mainStoryboard = [UIStoryboard storyboardWithName:@"iPadStoryboardOS6" bundle:nil];
}
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
NSLog(@"2");
if (iOSDeviceScreenSize.height == 480)
{
mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
} else {
mainStoryboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil];
}
self.initialViewController = [mainStoryboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.initialViewController;
[self.window makeKeyAndVisible];
}
答案 0 :(得分:1)
小心你如何检查iPad。 480px屏幕高度不包括iPhone 5.使用:
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)