dismissModalViewControllerAnimated无法正常工作 [英] dismissModalViewControllerAnimated not working

查看:131
本文介绍了dismissModalViewControllerAnimated无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有UINavigationController的UITabbarController. NavigationController中的视图显示了一个MVC(AddClockNavigationController).这个MVC有一个带有视图的笔尖和一个UINavigationController. NavigationController.view作为子视图添加到MVC的视图中.

I have a UITabbarController with a UINavigationController. The view in the NavigationController presents an MVC (AddClockNavigationController). This MVC has a nib with an view and an UINavigationController. The NavigationController.view is added as an subview to the MVC's view.

我的MVC中的NavigationController有两个按钮,即取消"和完成".当按下其中任何一个时,应关闭MVC. 这些按钮的IBAction位于UINavigationController的视图(AddClockViewController)中,但是只要按下它们,MVC就不会消失. 如果我将操作放到MVC中,它将消失. 如果我将函数放入MVC并使用[self.parentViewController myFunction]从viewController调用它,则该函数不会消失.

The NavigationController in my MVC has two buttons, an Cancel and an Done. When pressing either one of them the MVC should be dismissed. The IBActions of these buttons are in the UINavigationController's view (AddClockViewController), but whenever pressing them the MVC does not dissappear. If I put the actions into the MVC, it does disapear. If I put the function in my MVC and call it from my viewController using [self.parentViewController myFunction] it does not disappear.

如何使它从我的视线中消失?

How can I get it to disappear from my view?

我想我的演讲很混乱,但是希望您能理解.
我的IB的观点:

I guess my explenation is quite messy but I hope you understand it.
A view from my IB:

最诚挚的问候,
保罗·皮伦(Paul Peelen)

Best regards,
Paul Peelen

编辑 我已经尝试过使用[self dismissModalViewControllerAnimated:YES];[self.parentViewController dismissModalViewControllerAnimated:YES];[self.navigationController dismissModalViewControllerAnimated:YES];[self.parentViewController.navigationController dismissModalViewControllerAnimated:YES];进行此操作,并且如上所述,使用parentView中的函数将其消除.什么都行不通.

Edit I have tried this with [self dismissModalViewControllerAnimated:YES];, [self.parentViewController dismissModalViewControllerAnimated:YES];, [self.navigationController dismissModalViewControllerAnimated:YES];, [self.parentViewController.navigationController dismissModalViewControllerAnimated:YES]; and, as stated, with a function in the parentView dismissing it. Nothing works.

推荐答案

当某个视图控制器提供另一个视图控制器时,它将成为父视图控制器.因此,如果要关闭模态视图控制器,则必须选择:

When some view controller presents another one, it becomes a parent view controller. So if you want to dismiss your modal view controller, then you have to choices:

  1. 来自父视图控制器的调用

  1. from the parent view controller call

[self dismissModalViewControllerAnimated:是];

[self dismissModalViewControllerAnimated: YES];

OR

  1. 从模态视图控制器调用

  1. from the modal view controller call

[self.parentViewController dismissModalViewControllerAnimated:是];

[self.parentViewController dismissModalViewControllerAnimated: YES];

您实际上不需要导航控制器(因为您没有按/弹出任何视图控制器).只需将UINavigationBar添加到您的MVC并在其上放置按钮即可.然后向他们添加动作并执行选择#2. 您的代码无法正常运行,因为导航控制器没有父级,因为它没有以模态形式显示.

You actually don't need the navigation controller (cause you don't push/pop any view controllers). Just add the UINavigationBar to your MVC and place buttons on it. Then add actions to them and do choice #2. Your code is not working because navigation controller has no parent, as it wasn't presented as modal.

这篇关于dismissModalViewControllerAnimated无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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