我正在建立一个应用程序 – 当第一次启动它时,它要求用户做两件事情:
>选择国家
>接受T& Cs
从那里到家庭视图控制器.
我目前面临的问题是将第一个视图控制器从我的应用程序代理推送到屏幕上.我正在使用storyboards / Xcode 5 / iOS7
这是我提出的代码:
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil]; BBCounterySettingsViewController *controller = (BBCounterySettingsViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"CountrySettings"]; [navigationController pushViewController:controller animated:NO];
问题是应用程序崩溃时遇到以下错误的最后一行代码:
* Terminating app due to uncaught exception ‘NSInvalidArgumentException’,reason: ‘-[UIViewController
pushViewController:animated:]: unrecognized selector sent to instance
0x8e9a400’
任何人有什么想法我做错了什么?
解决方法
你期待self.window.rootViewController是一个UINavigationController,但它是一个UIViewController.这意味着你的故事板中的最外面的视图控制器的类型是错误的.
获取UINavigationController(在这种情况下应该工作)的更好的方法是在任何UIViewController上使用属性self.navigationController.
根据我的理解,您希望在用户第一次运行时让用户选择一些东西.你应该做的是呈现一个模态视图控制器,像这样:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //isFirstRun is some boolean you use to determine if it's the first run if(isFirstRun){ BBCounterySettingsViewController *controller = (BBCounterySettingsViewController *)[mainStoryboard instantiateViewControllerWithIdentifier: @"CountrySettings"]; [self.window.rootViewController presentViewController: controller animated:YES completion:nil]; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。