无法pushViewController进行子视图 [英] Unable to pushViewController for subview

查看:120
本文介绍了无法pushViewController进行子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UINavigationController,我有单独的UIViews,我在使用UISegmentControl之间切换。在切换视图时,我将视图作为子视图添加到导航控制器的视图中:

I have a UINavigationController and I have seperate UIViews that I switch between using a UISegmentControl. On switching the views, I add the view as a subview to my navigation controller's view:

[self.view addSubview:segmentTab1.view];

[self.view addSubview:segmentTab2.view];

然后,在子视图中,每个都有一个UITableView,但我的问题是,我无法在 didSelectRowAtIndexPath 方法中将一个新的viewController推入视图。

Then, in the subViews, each has a UITableView, but my issue is, that I am unable to push a new viewController into view in the didSelectRowAtIndexPath method.

正确调用该方法并通过设置断点,我可以看到推送视图的方法也被调用,但没有任何反应。这是推送它的代码:

The method is called correctly and by setting breakpoints, I can see the method for pushing the view gets called as well, but nothing happens. This is my code for pushing it:

[self.navigationController pushViewController:detailsViewController animated:YES];

我也试过

[super.navigationController pushViewController:detailsViewController animated:YES];

我做错了什么 - 或者是不可能用子视图做到这一点?

What am I doing wrong - or is is just not possible to do it with a subview?

推荐答案

当你调用-pushViewController时,哪个视图控制器是自己的?如果您从其中一个选项卡子视图中调用它,则自己可能没有从您添加到的顶级视图中引用导航控制器。您可以通过从顶级视图中获取导航控制器的内存地址并将其与子视图中的内容进行比较来验证这一点。显然,如果它是零或不匹配,那那就是你的问题。

When you call -pushViewController, which view controller is self? If you are calling that from within one of your tab subviews, self likely doesn't have a reference to the navigation controller from the top level view that you added it to. You can verify this by getting the memory address of the navigation controller from within the top level view and comparing it to what you have in the subview. Obviously if it's nil or doesn't match, then that's your problem.

当导航控制器被添加到导航堆栈本身时,你只能免费获得导航控制器-pushViewController你的子视图没有这样添加。

You only get a navigation controller "for free" when it's been added to the navigation stack itself with -pushViewController which your subviews haven't been added that way.

这篇关于无法pushViewController进行子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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