R Menke
R Menke

Reputation: 8411

UIAlertController gone crazy, point to settings when it should cancel

Anyone ever had an alert controller with a "cancel" action and just a return in the handler that does something?

Mine goes to the app settings....

I have another alert controller in another viewcontroller that does that. But that shouldn't affect this one????

alertControl.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (alertAction) -> Void in
            return
        }))

update:

Commented all other alertController out. (They were all in other view controller) now it doesn't do it anymore. What is this??

These are also only declared in a function when something goes wrong. When there is no connection,... They shouldn't even exist, unless the function gets called.

update 2 :

func checkAllSettingsForLocation() {
        if isTest != true {
        //println("should show this")

        let alertController = UIAlertController(title: "Scenix can't use your location", message: "Check Location Services under Privacy in the Settings App", preferredStyle: UIAlertControllerStyle.Alert)

        let goToSettingsAction = UIAlertAction(title: "Go to Settings", style: .Default, handler: {
            action in
            UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)
            return

            }
        )
        alertController.addAction(goToSettingsAction)

        let ignoreNoCamAction = UIAlertAction(title: "Cancel", style: .Default, handler: {
            action in
            self.launch = self.launch - 1
            return

            }
        )
        alertController.addAction(ignoreNoCamAction)

        self.presentViewController(alertController, animated: true, completion: nil)
        }
    }

Update 3:

Looks more and more like an Xcode Bug.

Building for release / through test flight and the bug is there. Do a normal debug build and all is fine....


dirty fix =>

Wrap the action from any alert controller in an if statement that checks the alert controller title. Can never throw an exception or result in finding a nil and fixed my problem.

Upvotes: 1

Views: 465

Answers (1)

hidden-username
hidden-username

Reputation: 2697

Try using nil instead of return,

let cancel = UIAlertAction(title: "Ok", style: .Cancel, handler: nil) alertController.addAction(cancel)

I also have some other setting destination alert controllers, and this has worked fine for me.

Upvotes: 2

Related Questions