Reputation: 1145
Hi guys i have some little problem. So i use three storyboard in my project, there are iPhone 4s storyboard/iPhone 5 and i created for iPad also. So for choose storyboard i use this code:
UIStoryboard * mainStoryboard = nil ;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
mainStoryboard = [ UIStoryboard storyboardWithName : @ "iPhone5" bundle : nil ] ;
} else {
mainStoryboard = [ UIStoryboard storyboardWithName : @ "iPhone4s" bundle : nil ] ;
}
self.window = [ [ UIWindow alloc ] initWithFrame : [ [ UIScreen mainScreen ] bounds ] ] ;
self.window.rootViewController = [ mainStoryboard instantiateInitialViewController ] ;
[ self.window makeKeyAndVisible ] ;
Work perfectly but not for iPad. After this code my storyboard for iPad does not see. How to choose iPad storyboard with all this storyboards. I understand my problem but i can not find good solve. How it's create? Thanks.
Also i tried this...but nothing.
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone)
{
UIStoryboard * mainStoryboard = nil ;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
mainStoryboard = [ UIStoryboard storyboardWithName : @ "iPhone5" bundle : nil ] ;
} else {
mainStoryboard = [ UIStoryboard storyboardWithName : @ "iPhone4s" bundle : nil ] ;
}
}
else
{
UIStoryboard *appropriateStoryboard = [self storyboard];
self.window.rootViewController = [appropriateStoryboard instantiateInitialViewController];
return YES;
- (UIStoryboard *)storyboard
{
NSString *storyboardName = @"iPadMyBoard";
if ([self isPad]) {
storyboardName = [storyboardName stringByAppendingString:@""];
}
return [UIStoryboard storyboardWithName:storyboardName bundle:nil];
}
-(BOOL)isPad
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
}
Upvotes: 1
Views: 195
Reputation: 906
You can use this code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *appropriateStoryboard = [self storyboard];
self.window.rootViewController = [appropriateStoryboard instantiateInitialViewController];
return YES;
}
- (UIStoryboard *)storyboard
{
NSString *storyboardName;
if ([self isPad])
{
storyboardName = @"iPadMyBoard";
}
else
{
if ([self isPhone5])
{
storyboardName = @"iPhone5";
}
else
{
storyboardName = @"iPhone4s";
}
}
return [UIStoryboard storyboardWithName:storyboardName bundle:nil];
}
-(BOOL)isPad
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
}
-(BOOL)isPhone5
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568){
return YES;
}
return NO;
}
Upvotes: 1