In a project I'm working on, I had to write a UIAlert helper module that would display popups here and there in my iOS app. The popups are written as class functions that I can simply call anywhere in the code (the class is static and so are all the functions).
I am now encountering a very weird bug where if you dismiss an alert once, then open it again, its actions don't function anymore (as in, the action handler is not called). It does work if you click the action the first time the popup is displayed, though...
Here is the code for the specific popup for which this bug occurs (no other popups are affected whatsoever):
static func popSkipWalkthrough() {
let alert = UIAlertController(title: "Skip", message: "whatever", preferredStyle: .Alert)
alert.addAction(cancelAction)
alert.addAction(skipWalkthroughAction)
appDelegate.window!.rootViewController!.presentViewController(alert, animated: true, completion: nil)
}
The skipWalkthroughAction
is defined as following:
static let skipWalkthroughAction = UIAlertAction(title: "Continue", style: .Default, handler: { (action: UIAlertAction!) -> Void in
appDelegate.setWindowViewTo("NavCtrl", navigateTo: false)
CallIn.Settings.didWalkthrough = true
})
And the cancelAction
is defined as :
static let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
This popup in particular is shown every time you press the 'skip' button in the last step of a walk-through...
I have tried a few leads on what the cause for this behavior is, and I think it might have something to do with the popup not really being deallocated, but I'm not sure at all at this point...
Any ideas ?