Reputation: 21
How can i run the action for the “keep” button without dismissing the UIAlertController ? I found solutions for disabling the button but it’s not what i need.
newItemPrompt = UIAlertController(title: "title", message: "message", preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (action) -> Void in
println("ok")
})
let keepAlert = UIAlertAction(title: "keep", style: .Default) { (action) -> Void in
println("keep alert view")
}
newItemPrompt.addAction(okAction)
newItemPrompt.addAction(keepAlert)
newItemPrompt.addAction(cancelAction)
self.presentViewController(newItemPrompt, animated: true, completion: nil)
Upvotes: 2
Views: 6283
Reputation: 21
You may want to create your own View Controller where you decide what all the buttons do. However, if you really want to use UIAlertController, you could show the same alert again when the user clicks on the "keep" button:
let keepAlert = UIAlertAction(title: "keep", style: .Default) { (action) -> Void in
self.presentViewController(newItemPrompt, animated: true, completion: nil)
println("keep alert view")
}
The alert will disappear for a second and re-appear then. It's not ideal, but it's a workaround.
Upvotes: 2
Reputation:
Disabling the button is probably the only way to disable that method, either that or delete the code. I'll do more research but thats all you can do for now :)
Upvotes: 0