【问题标题】:segueForUnwindingToViewController causing "Warning: Attempt to present <...> on <...> which is already presenting <...>"segueForUnwindingToViewController 导致“警告:尝试在已呈现 <...> 的 <...> 上呈现 <...>”
【发布时间】:2015-05-22 19:52:38
【问题描述】:

我正在构建一个应用程序,最近发现了由传统 segues 引起的巨大内存泄漏。 因此,我了解了 unwind segue。如果我简单地使用,一切都会很好:

    @IBAction func prepareForUnwindToMainFromFriends(segue: UIStoryboardSegue) {
    }

内存泄漏已解决,“一切都很棒”。但是从 UI 的角度来看,这个解决方案看起来很难看。所以我从this website 实现了这个功能。并稍作改动。

override func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue {
    return UIStoryboardSegue(identifier: identifier, source: fromViewController, destination: toViewController) {
        let fromView = fromViewController.view
        let toView = toViewController.view
        if let containerView = fromView.superview {
            let initialFrame = fromView.frame
            var offscreenRect = initialFrame
            var offscreenRectFinal = initialFrame
            offscreenRect.origin.x += CGRectGetWidth(initialFrame)
            offscreenRectFinal.origin.x -= CGRectGetWidth(initialFrame)
            toView.frame = offscreenRect
            containerView.addSubview(toView)
            let duration: NSTimeInterval = 1.0
            let delay: NSTimeInterval = 0.0
            let options = UIViewAnimationOptions.CurveEaseInOut
            let damping: CGFloat = 0.9
            let velocity: CGFloat = 4.0
            UIView.animateWithDuration(duration, delay: delay, usingSpringWithDamping: damping,
                initialSpringVelocity: velocity, options: options, animations: {
                    toView.frame = initialFrame
                    fromView.frame = offscreenRectFinal
                    
                }, completion: { finished in
                    fromView.removeFromSuperview()
                    if let navController = toViewController.navigationController {
                        navController.popToViewController(toViewController, animated: false)
                    }
            })
        }
    }
}

但现在我收到一条错误消息:

2015-05-12 08:47:31.841 PING0.4[4343:1308313] Warning: Attempt to present <NotificationViewController: 0x177030b0>  on <PING0_4.ViewController: 0x16271000> which is already presenting <NotificationViewController: 0x1a488170>

我在我的应用程序中被阻止。我可以从 VC1 到 VC2,然后再回到 VC2,但我不能再回到 VC1。这个segue好像只能用一次。

有人知道发生了什么吗?

【问题讨论】:

  • 我猜你搞砸了pushpresent 导航。仔细检查
  • 这个问题:stackoverflow.com/questions/22421845/… 如果你想限制多个segue的发生可能会有所帮助。
  • @Quentin Malgaud 了解更多详情:stackoverflow.com/questions/19560198/…
  • @Quentin 你怎么给segue...是从视图或按钮
  • 我试图弄清楚推送和呈现之间的区别。整个uiviewcontroller管理其实。 Segues 由按钮和视图触发。我正在尝试找出@zala 解决方案,但我没有在 objc 中编码。不过我会朝那个方向挖掘。到目前为止,感谢您的 cmets。

标签: ios swift segue uistoryboardsegue unwind-segue


【解决方案1】:

使用上述过渡动画代码创建用于展开 segue 的示例代码。查看SampleUnwind 项目,该项目将帮助您了解 unwind segue(以及它是多么简单)。

在项目中有一个导航控制器,里面有三个视图控制器(Home->First->second)。

在 Home 控制器中创建以下展开操作,当点击第二个控制器的“Home”按钮时将调用该操作(简单的展开内容)。

@IBAction func unwindToHomeViewController(segue:UIStoryboardSegue) {
}

我创建了TempNavigationController 子类化UINavigationController 并将TempNavigationController 设置为情节提要中的导航控制器。 您给出的上述方法在其中包含,因为根据以下参考,这将是 fromViewController 的容器。

参考:Apple 有关在两个子视图控制器之间转换的文档。

您可以将其与您的项目进行比较,也许您可​​以在您的项目中找到任何重复(或多个/错误)的 segue。

【讨论】:

    猜你喜欢
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多