ViewController出现两次过渡 [英] ViewController Appears to Transition Twice

查看:123
本文介绍了ViewController出现两次过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题摘要

我的mainVC->第二个VC转换似乎运行了两次.但是,奇怪的是第二个VC的viewDidLoad只运行一次.这是我项目中唯一出现此问题的过渡.

My mainVC --> second VC transtion appears to run twice. However, what's odd is that the second VC's viewDidLoad only runs once. This is the only transition in my project that has this problem.

我对此进行了研究,发现有两次加载两次的问题,但两次都与我的过渡不匹配,但一次加载一次.常见问题(例如有人在情节提要中添加了两个标记)没有出现在我的项目中:

I have researched this and found load-twice issues but none are a match to my transition twice but load once scenario. Common issues, like someone having added two segues in the storyboard, do not appear in my project:

在我的第一个/根视图控制器(称为mainVC)中,我以编程方式在viewDidLoad中添加了一个边缘平移手势:

In my first/root view controller (called mainVC) I programmatically add an edge pan gesture in the viewDidLoad:

        let panLeftEdgeGesture_MainVC = UIScreenEdgePanGestureRecognizer(target: self, action: "panLeftEdge_toLifeList:")
        panLeftEdgeGesture_MainVC.edges = .Left
        view.addGestureRecognizer(panLeftEdgeGesture_MainVC)

当用户滑动平移手势时,它会触发一个函数,该函数将segue调用到我的下一个VC.问题是,VC转换出现两次,然后一切正常.没有任何中断或崩溃.如果单击自定义后退按钮,则退回到mainVC只会出现一次.

When the user swipes that pan gesture, it triggers a function that calls a segue to my next VC. Problem is, that VC transition appears twice and then everything works fine after that. Nothing breaks or crashes. If I click my custom back button, the unwind back to mainVC only appears once.

对原因的实验

这是一个很奇怪的部分:为了理解所理解的内容,我插入了一些println代码,这是控制台输出的内容:

Here's the weird part: in an attempt to understand what was understand, I inserted some println code and here's what the console prints:

No matching prepareForSegue: So did nothing to prepare.
LifeList_CollectionView viewDidLoad did run
Pan segue from mainVC to Life Lists did run
No matching prepareForSegue: So did nothing to prepare.

第一行是prepareForSegue运行.它说什么也没做",因为在我的prepareForSegue中,它检查哪个segue正在运行,有时会传递一些代码.在这种情况下,prepareForSegue除了打印该行外什么都不做.

That first line is the prepareForSegue running. It says "did nothing" because in my prepareForSegue it checks which segue is running and sometimes it'll pass some code. In this case, the prepareForSegue does nothing but print that line.

第二行是第二个VC的viewDidLoad运行.

The second line is the second VC's viewDidLoad running.

第三行对我来说似乎很奇怪且混乱,但是我不是专家.该println在mainVC中,并从平移手势调用的函数进行打印,这是首先触发segue的函数.为什么在第二个VC的viewDidLoad之前无法打印?

The third line seems weird and out of order to me, but I'm no expert. That println is in the mainVC and prints from the function called by the pan gesture, this is the function that triggered the segue in the first place. Why would this not print before the 2nd VC's viewDidLoad?:

func panLeftEdge_toLifeList(sender: UIScreenEdgePanGestureRecognizer) {
    performSegueWithIdentifier("segueToLifeLists", sender: nil)
    println("Pan segue from mainVC to Life Lists did run")
}

第四行是mainVC的prepareForSegue第二次运行.但是,即使在视觉上我看到过渡发生了两次,我也看不到控制台打印第二个viewDidLoad.

The fourth line is the mainVC's prepareForSegue running a second time. However, I don't see the console printing a second viewDidLoad, even though visually I see the transition happen twice.

您知道什么原因会导致这种奇怪的行为,或者至少有任何技巧可以阻止这种行为?

推荐答案

基本上,您只需要重命名目标视图控制器的类即可.

Essentially you simply need to rename the destination view controller's class.

有关完整答案,请参见这篇文章:

For full answer see this post:

视图控制器加载两次-如何修复?

这篇关于ViewController出现两次过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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