[英]Instantiating storyboard programmatically in appdelegate
I decided to use different storyboards for ios6 and and ios7 and so I need to instantiate storyboards in code. 我决定为ios6和ios7使用不同的情节提要,因此我需要在代码中实例化情节提要。 I have this method in the app delegate´s
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
我在应用程序委托的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
有此方法
but nothing happens, it always just instantiate the storyboard named iPadStoryboard
when run on the iPad simulator, I have deleted the Main interface´s from the info.plist. 但是什么也没发生,在iPad模拟器上运行时,它总是只实例
iPadStoryboard
为iPadStoryboard
的情节iPadStoryboard
,我已经从info.plist中删除了Main界面。 Any idea what´s happening here? 知道这里发生了什么吗?
- (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];
}
Be careful how you check for iPad. 请注意如何检查iPad。 480px screen height doesn't cover iPhone5.
480像素的屏幕高度不能覆盖iPhone5。 Use:
采用:
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.