self.presentingViewController返回UITabBarController,而不是使用presentModalViewController推送它的视图控制器 [英] self.presentingViewController returns UITabBarController not the view controller pushing it with presentModalViewController

查看:215
本文介绍了self.presentingViewController返回UITabBarController,而不是使用presentModalViewController推送它的视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于标签的应用程序。其中一个视图就是推送模态视图控制器。如果我在模态视图控制器中调用 self.presentingViewController ,它将返回标签栏控制器,而不是推送它的视图控制器

I have a tab based application. One of the views in it is pushing a modal view controller. If I call self.presentingViewController within a modal view controller, it returns tab bar controller, not the view controller which is pushing it.

我在这里缺少什么?有没有可靠的方法来返回视图控制器提升模式?

What am I missing here? Is there a reliable way to return a view controller raising modal?

谢谢。

推荐答案

这是一个iPhone应用程序吗?如果是这样,那就解释了混乱。在iPhone上,唯一的演示风格是 UIModalPresentationFullScreen - 这相当于说iPhone上的,根视图控制器始终是呈现视图控制器。好吧,在标签栏界面中,UITabBarController的视图是根视图控制器。

Is this an iPhone app? If so, that explains the confusion. On iPhone, the only presentation style is UIModalPresentationFullScreen - which amounts to saying that on iPhone, the root view controller is always the presenting view controller. Well, in a tab bar interface, the UITabBarController's view is the root view controller.

您会注意到iPhone上的模态视图不会取代视图控制器的视图;它取代了整个界面,这意味着它取代了标签栏控制器的视图。这是因为标签栏控制器真的 呈现视图控制器。

You'll notice that on iPhone the modal view doesn't replace your view controller's view; it replaces the whole interface, meaning that it replaces the tab bar controller's view. This is because the tab bar controller really is the presenting view controller.

我猜你在iPhone上真的不应该发送 presentViewController: presentModalViewController:到标签栏控制器包含的视图控制器。您应该将其发送到标签栏控制器。因此,消息将被路由到标签栏控制器。

I'm guessing that on iPhone you really should not be sending presentViewController: or presentModalViewController: to a view controller contained by a tab bar controller. You should be sending it to the tab bar controller. The message is therefore being routed to the tab bar controller for you.

因此, presentsViewController的值将不会发生任何有趣的事情除非你在iPad上。在iPad上,可以使模态视图替换视图控制器的视图。为此,模态视图的 modalPresentationStyle 必须是 UIModalPresentationCurrentContext 。在这种情况下,它的 presentsViewController 可以实际上是推动模态视图控制器的视图。

So, nothing interesting is going to happen with the value of presentingViewController unless you're on an iPad. On an iPad, you can make the modal view replace the view controller's view. To do so, the modal view's modalPresentationStyle must be UIModalPresentationCurrentContext. And in that case, its presentingViewController can in fact be the view that "pushes the modal view controller".

这篇关于self.presentingViewController返回UITabBarController,而不是使用presentModalViewController推送它的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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