Problem Summary
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:
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)
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.
Experiment to Shed Light on the Cause
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.
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.
The second line is the second VC's viewDidLoad running.
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")
}
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.
Any idea what could cause such an odd behavior or, at the least, any tricks to stop this behavior?