iOS 5尝试从模态视图中推送ViewController [英] iOS 5 Trying to pushViewController from modal view

查看:136
本文介绍了iOS 5尝试从模态视图中推送ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS 5选项卡式应用程序,使用故事板。

I have an iOS 5 Tabbed Application, using Storyboards.

我的Tabbar控制器指向三个导航控制器。

My Tabbar Controller points to three Navigation Controllers.

从其中一个开始,流程如下所示:

From one of them, the flow looks like this:

开始视图 - >照片视图(模态) - >目录视图

Start view --> Photo view (modal) --> Catalog view

在照片屏幕上,我有一个包含以下代码的按钮:

On the photo screen, I have a button with the following code:

- (IBAction)acceptPhotoButtonPressed:(id)sender {
    UIViewController *catalogView = [self.storyboard instantiateViewControllerWithIdentifier:@"CatalogView"];
    [self.navigationController pushViewController:catalogView animated:YES];
}

我试过去玩 presentsViewController parentViewController - 甚至将类型转换为 UINavigationController 。这会导致它崩溃,并显示以下错误消息:

I've tried fooling around with presentingViewController, parentViewController - even type casted those to a UINavigationController. That causes it to crash, with the following error message:

2012-04-06 00:32:45.808 myapp[19345:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController pushViewController:animated:]: unrecognized selector sent to instance 0x18d0d0'

所以这告诉我,我没有拿到 UINavigationController ,而是 UITabBarController

So that tells me that I haven't got hold of a UINavigationController, but a UITabBarController.

有什么方法吗?

推荐答案

推送样式segue只能从由 UINavigationController 管理的视图控制器完成。如果你试图这样做,否则什么都不会发生。

A "push" style segue can only be done from a view controller that is being managed by a UINavigationController. If you try to do so otherwise nothing will happen.

你应该在你的问题中描述的模态显示你的照片视图,你应该显示一个UINavigationController实例作为模态查看并使照片查看导航视图的根视图控制器。 (这可以通过故事板设置)。然后你的推送segue将工作。

Instead of displaying your Photo view modally as you describe in your question, you should display an instance of UINavigationController as the modal view and make the Photo View the root view controller of the navigation view. (This can all be set up through storyboard). Then your push segue will work.

如果你不希望顶部导航栏出现在你的第一个视图控制器(照片视图)
你可以使用:

If you do not wish for the top navigation bar to appear on your first view controller (Photo view) you can use:

[self.navigationController setNavigationBarHidden:YES animated:NO]

这将隐藏顶部导航栏。一旦你把一个新的视图控制器,如果你想要的导航栏,以重新出现在一个和任何后续视图控制器,你必须setNavigationBarHidden设置为NO在新的视图 - 控制。

This will hide top nav bar. Once you push a new view controller, if you want the nav bar to reappear on that one and any subsequent view controllers you'll have to set setNavigationBarHidden to NO on the new viewcontroller.

[self.navigationController setNavigationBarHidden:NO animated:NO]

这篇关于iOS 5尝试从模态视图中推送ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆