thellimist / EZAlertController

Easy Swift UIAlertController

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Always receive this warning!

dzpt opened this issue · comments

commented

Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x7aa4b600>)

I'm not certain but you probably initialized your View Controller like
var myViewController = UIViewController()
whereas you should declared it as
var myViewController: UIViewController!

source: http://stackoverflow.com/questions/32282401/attempting-to-load-the-view-of-a-view-controller-while-it-is-deallocating-uis

commented

I have UINavigationController in the root.
In the first ViewController i prepare segue to call to other view:

_ = segue.destinationViewController as! DetailViewController

In this DetailController i have a UITableview and each cell has 1 button.

cell.captionprice.addTarget(self, action: #selector(DetailViewController.DownloadConfirm(_:)), forControlEvents: .TouchUpInside)

In the method DownloadThemeConfirm i fire EZAlertController and get this error.
This error happens only with closure.

I've tested with original UIAlertController and don't have this error

commented

This error happens only with
EZAlertController.alert("Title", message: "Message", buttons: ["First", "Second"]) { (alertAction, position) -> Void in if position == 0 { print("First button clicked") } else if position == 1 { print("Second button clicked") } }

and if i call
EZAlertController.alert("Title", message: "Message", acceptMessage: "OK") { () -> () in print("cliked OK") } it works fine. ??!

I couldn't replicate the error. If you find the reason can you also write a comment on your findings?

commented

I've a hard test, and it seems error come from this convinience init:

convenience init(title: String?, message: String?, preferredStyle: UIAlertControllerStyle, buttons:[String], tapBlock:((UIAlertAction,Int) -> Void)?, textFieldsCompletitionHandler : [(UITextField -> Void)?]? ) {
        self.init(title: title, message: message, preferredStyle:preferredStyle)

I change the code to

public class func alert(title: String, message: String, buttons:[String],view:UIViewController, tapBlock:((UIAlertAction,Int) -> Void)?) -> UIAlertController{
        let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
        for (buttonIndex,buttonTitle) in buttons.enumerate() {
            let action = UIAlertAction(title: buttonTitle, preferredStyle: .Default, buttonIndex: buttonIndex, tapBlock: tapBlock)
            alert.addAction(action)
        }
        view.presentViewController(alert, animated: true, completion: nil)
        return alert
    }

And it works now.

I think this link is very useful

Both bugs shouldn't be problematic so we can simply ignore the warning for now. I do that too and there weren't any problems yet - just that warning in the log.