shakked shakked - 6 months ago 34
Swift Question

UIAlertController title and message not appearing

I am using this code:

let alertController = UIAlertController(title: "Default AlertController", message: "A standard alert", preferredStyle: .Alert)

let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action:UIAlertAction!) in
print("you have pressed the Cancel button");
}
alertController.addAction(cancelAction)

let OKAction = UIAlertAction(title: "OK", style: .Default) { (action:UIAlertAction!) in
print("you have pressed OK button");
}
alertController.addAction(OKAction)

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


And this is what it looks like:

enter image description here

Here is is what the code around the presentation looks like. I am checking the auth status of CloudKit and then presenting an alert if there is an error:

dispatch_async(dispatch_get_main_queue(), {
self.activityIndicator.stopAnimating()

guard let user = user where succeeded && error == nil else {
if let error = error {
switch error {
default:

let alertController = UIAlertController(title: "Default AlertController", message: "A standard alert", preferredStyle: .Alert)

let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action:UIAlertAction!) in
print("you have pressed the Cancel button");
}
alertController.addAction(cancelAction)

let OKAction = UIAlertAction(title: "OK", style: .Default) { (action:UIAlertAction!) in
print("you have pressed OK button");
}
alertController.addAction(OKAction)

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

Answer

I inherited this project and I realized that my colleague had written a UIAlertController category that was giving me the weird bug mentioned above.