【发布时间】:2014-05-20 20:55:37
【问题描述】:
大家好,我有一些小问题。所以我在我的项目中使用了三个故事板,有 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);
}
【问题讨论】:
标签: xcode ipad storyboard uistoryboard