我决定为 ios6 和 ios7 使用不同的 Storyboard,因此我需要在代码中实例化 Storyboard。我在应用程序委托(delegate)的 - (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
但什么也没发生,它总是只是实例化名为 iPadStoryboard
的 Storyboard,当在 iPad 模拟器上运行时,我已经从 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];
}
请注意检查 iPad 的方式。 480px 屏幕高度不覆盖 iPhone 5。使用:
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
关于ios - 在 appdelegate 中以编程方式实例化 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18839150/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |