【问题标题】:View over view breaks hierarchical查看视图打破层次结构
【发布时间】:2016-06-15 08:29:58
【问题描述】:

我正在使用MZFormSheetPresentationController 将 ViewController2(按照建议嵌入到导航控制器中)显示为“弹出”,而不是 ViewController1。

我的 ViewController1 有一个搜索栏、一个 UISegmentedControl 和一个表格视图:

当用户单击搜索栏书签按钮时,会显示弹出窗口。

我想在用户单击完成按钮时关闭弹出窗口,并且使用 self.dismissViewControllerAnimated(true, completion: nil) 方法效果很好,但我正在寻找更多.我想再次展示 ViewController1,以便 tableView 重新加载数据。 我试过了:

self.dismissViewControllerAnimated(true, completion: nil)
        print("Dismissed")

        //goToTickets
        let next = self.storyboard?.instantiateViewControllerWithIdentifier("myTabBar") as! UITabBarController
        self.presentViewController(next, animated: true, completion: nil)

但我收到此错误:

警告:尝试呈现不在窗口层次结构中的视图!

弹出窗口消失,但我无法呈现 ViewController。

我该怎么办?

提前致谢。

编辑

这是我的 ViewController2,标识符为“navigationFilter”

还有我的标签栏:

【问题讨论】:

    标签: ios swift uiview tableview uisegmentedcontrol


    【解决方案1】:

    当你在试图呈现下一个 ViewController 时,你必须等待完成处理程序,然后像这样呈现下一个视图控制器:

    self.dismissViewControllerAnimated(true, completion: {
        let next = self.storyboard?.instantiateViewControllerWithIdentifier("myTabBar") as! UITabBarController
        self.presentViewController(next, animated: true, completion: nil)
    })
    

    【讨论】:

    • 我试过了,还是报错,我在viewController2中写了这段代码
    • 您的视图层次结构中的某处有问题,MZFormSheetPresentationController 与普通模态演示控制器的工作方式相同,因此您应该尝试使用普通演示,然后使用 MZFormSheetPresentationController。
    • 我用我的应用程序结构更新了我的问题。我真的不知道我是怎么得到这个错误的..
    • 您正在尝试在视图控制器上呈现,该控制器不再出现在视图 Hierarchy TabBarController ----/ --> FormSheet 上,并且您可能正在尝试在 FormSheet 上呈现,您必须在 TabBarController 上再次呈现,你可以使用这个 self.presentingViewController 属性。
    • 很抱歉占用了您的时间,但了解它的工作原理对我来说非常重要。我需要在 self.dismissViewControllerAnimated 方法之前或之后调用“self.presentingViewController”?谢谢
    猜你喜欢
    • 2021-08-01
    • 2013-06-16
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多