在UINavigationController中推送View Controller [英] Push a View Controller in a UINavigationController

查看:78
本文介绍了在UINavigationController中推送View Controller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带导航控制器的标签视图控制器。在第一个标签项中,我单击视图中的一个按钮,弹出一个带有动画的视图:YES。

I have a tab view controller with a navigation controller. In the first tab item I click on a button in a view that pops up a view with animated: YES.

然后当该视图完成后,我点击另一个关闭的按钮它。喜欢:

Then when that view is done I hit another button that dismisses it. Like:

                   [self dismissViewControllerAnimated:NO completion:^{

                        ProfilesViewController *profile = [[ProfilesViewController alloc] init];
                        [self.navigationController pushViewController:profile animated:YES];

                        //SHOW YOUR NEW VIEW CONTROLLER HERE!
                    }];

但每次运行此代码时,它都会关闭视图,不会推送配置文件控制器,并显示从第一个标签栏项目查看。

But everytime this code runs, it dismisses the view, DOES NOT push the profiles controller, and shows the view from the first tab bar item.

如何使用后退箭头将ProfilesViewController推送到屏幕?

How do I push the ProfilesViewController to the screen with a Back arrow?

推荐答案

如果您使用 dismissViewControllerAnimated 来解除这意味着VC是以模态方式呈现的。因此,它没有导航控制器(因此 self.navigationController 为零)因此无法将任何东西推入导航控制器。

If you are using dismissViewControllerAnimated to dismiss that means that the VC is presented modally. As such, it doesn't have a navigation controller (so self.navigationController is nil) and thus it can't push anything into the navigation controller.

你真的应该向控制器添加一个属性,它是一个委托或完成块,可以用来从另一个控制器(显示它的控制器)推动控制器来解除并推送控制器。

You should really add a property to the controller which is a delegate or a completion block which can be used to push the controller from another controller (the one that presents it) to dismiss and push the controller.

第二种选择是通过导航控制器,使用一个块的代码数量相似但不太好。

A second option is to pass the navigation controller, it's a similar amount of code to using a block but not so good.

一个糟糕的选择是使用 parentViewController 来查找合适的导航控制器,但这很糟糕。

A crappy option is to use the parentViewController to find the appropriate navigation controller, but that sucks for many reasons.

这篇关于在UINavigationController中推送View Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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