将 iPad 故事板添加到现有的 iphone 项目
Posted
技术标签:
【中文标题】将 iPad 故事板添加到现有的 iphone 项目【英文标题】:Add iPad storyboard to existing iphone project 【发布时间】:2013-07-28 16:33:41 【问题描述】:我为 iphone/ipod 用户创建了我的项目。现在我想让它也适用于 ipad 用户。我有 2 个故事板; 3.5 英寸和 4 英寸。
这是我的步骤:
1)我创建了一个新的故事板。文件 - 新文件 - 用户界面 - iPad 故事板。
2)我将目标设备从 iphone 更改为通用。
3)我在 iPad 部署信息部分设置了主情节提要。
4) 最后,我复制了 4 英寸 iPhone 故事板上的所有内容,并将其粘贴到 ipad 的新故事板上。 (我没有改变任何东西,包括屏幕尺寸)
我试图在新的故事板上只放置一个视图控制器,但结果是一样的。
然后我在 iPad 模拟器上运行并构建了我的应用程序。我在下面得到一个错误:
2013-07-28 19:02:42.151 Test[40038:12203] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[ViewController topViewController]:
unrecognized selector sent to instance 0x7888940'
*** First throw call stack:
(0x1b02012 0x1573e7e 0x1b8d4bd 0x1af1bbc 0x1af194e 0x252b 0x2626 0x4b5157 0x4b5747
0x4b694b 0x4c7cb5 0x4c8beb 0x4ba698 0x194cdf9 0x194cad0 0x1a77bf5 0x1a77962 0x1aa8bb6
0x1aa7f44 0x1aa7e1b 0x4b617a 0x4b7ffc 0x1d5d 0x1c85)
libc++abi.dylib: terminate called throwing an exception
这是在 AppDelegate.m 中
-(void)initializeStoryBoardBasedOnScreenSize
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
// The ios device = iPhone or iPod Touch
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 480)
// iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iphone35" bundle:nil];
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;
// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
if (iOSDeviceScreenSize.height == 568)
// iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;
// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
// The iOS device = iPad
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
谁能解释一下怎么回事?
【问题讨论】:
【参考方案1】:拆分视图控制器中的最后一个对象不是 UINavigationController。检查你的故事板。
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
【讨论】:
谢谢帖木儿。我完全忘记了我改变了控制器。 没问题。祝你好运,@Taha。以上是关于将 iPad 故事板添加到现有的 iphone 项目的主要内容,如果未能解决你的问题,请参考以下文章
ios - 我已经成功地将故事板 UIWebView 连接到 iPhone 的控制器,但不能为 iPad 做
iPad SplitViewController - 使用 iPhone 故事板 ViewController
xamarin c# 使用两个故事板,一个用于 iPad,另一个用于 iPhone?