大家好我有点问题。所以我在我的项目中使用了三个故事板,还有iPhone 4s故事板/ iPhone 5,我也为iPad创建。因此,对于选择故事板,我使用此代码:
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 ] ;
完美的工作但不适用于iPad。在这段代码之后,我的iPad故事板没有看到。如何选择所有这些故事板的iPad故事板。我理解我的问题,但我找不到好的解决方案。它是如何创造的?感谢。
我也尝试了这个...但没有。
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);
}
答案 0 :(得分:1)
您可以使用此代码
- (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;
}