Multiple Uialertcontrollers in iOS

Multiple UIAlertControllers to show one after the other in Swift

OK, I've figured it out, what I've done is get the code to be ran when I press OK on the view , so that it checks the other sections then pops another one if need be.

I've putted it in after

action -> Void in

thanks a lot

How to pass multiple handlers in UIAlertAction

It's not totally clear what you're asking, but if you are trying to figure out which button was pressed so that you can execute different methods for each one you can do something like this:

@IBAction func buttonClicked(_ sender: UIButton) {
let alert = UIAlertController(title: "Select Value", message: nil, preferredStyle: .actionSheet)
for list in self.listValue {
alert.addAction(UIAlertAction(title: list.value, style: .default, handler: { (action) in
// How do I call different handlers here?
// I'll need to retrieve alert.title in these handlers
switch action.title {
case "Value A":
print("It's Value A")
case "Value B":
print("It's Value B")
default:
print("We didn't implement anything for this value")
}
}))
}
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel, handler: nil))
self.present(alert, animated: false, completion: nil)
}

Multiple lined UIAlertController message

It will work with \n as edited.

let alert = UIAlertController(title: "Title",
message: "message: \n message",
preferredStyle: UIAlertControllerStyle.alert)

let cancelAction = UIAlertAction(title: "OK",
style: .cancel, handler: nil)

alert.addAction(cancelAction)
self.present(alert, animated: true, completion: nil)


Related Topics



Leave a reply



Submit