【发布时间】:2016-12-11 03:55:51
【问题描述】:
当我在我的 iPhone 4 上使用 Xcode 7.3.1 运行原始 (Objective-C) 主从应用程序模板时,该设备上可能有最新的 iOS (7.1.2),它崩溃了。我可能无法更改设置为 iOS 9.3 的 Base SDK,但我使用的是正确的体系结构和部署目标。为什么会崩溃?
崩溃代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
/**CRASH**/navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
splitViewController.delegate = self;
return YES;
}
调试器说:
2016-08-04 21:14:26.240 Master-Detail-Application-2[766:60b] -[MasterViewController topViewController]: unrecognized selector sent to instance 0x16d61c20
2016-08-04 21:14:26.246 Master-Detail-Application-2[766:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MasterViewController topViewController]: unrecognized selector sent to instance 0x16d61c20'
*** First throw call stack:
(0x30dbef83 0x3b56fccf 0x30dc2917 0x30dc1203 0x30d10768 0x396a7 0x3364b587 0x3364aedb 0x3364556b 0x335e16e9 0x335e0851 0x33644ca9 0x35bf9aed 0x35bf96d7 0x30d89a67 0x30d89a03 0x30d881d7 0x30cf2ebf 0x30cf2ca3 0x33643ed1 0x3363f14d 0x3a945 0x3ba7cab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
【问题讨论】:
-
topViewController是UINavigationController的方法,而不是UIViewController。 -
@maddy 这是我从代码中看到的,没错。
-
但错误表明您正在尝试在您的
MasterViewController上调用topViewController,而不是UINavigationController。 -
@rmaddy 好点,但我标记了崩溃点。该模板适用于模拟器,我相信 iOS 9.3。
标签: objective-c ios7 xcode7 iphone-4