prone666 prone666 - 3 months ago 28
Swift Question

Swift-tvOS dismissing UIAlertController

I am doing app for

tvOS
and I have problem with canceling
UIAlertController
. I am presenting a
UIAlertController
on top of a normal
UIViewController
. When I push Menu button on tv remote to dismiss the alert, the parent view controller is dismissed first and when i press menu button for the second time,
UIAlertController
disappeared correctly, but after the parent view controller, which i don't want to dismiss.

func showTextDescription(message:String?) {
let allertController=UIAlertController(title: title, message: message, preferredStyle: .ActionSheet)

// Cancel action (is invisible, but enables escape)
allertController.addAction(UIAlertAction(title: nil, style: .Cancel, handler: nil))

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


How can i dismiss only
alertcontroller
?
Thanks.

Answer

Just call this line of code when you want to dismiss the alert controller.

allertController.dismissViewControllerAnimated(true, completion: nil)

Or you can add an alert action.

let alertAction: UIAlertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)
allertController.addAction(alertAction)
Comments