Я создал UIAlertController
с тремя кнопками действий, теперь я хочу установить текст на TextView
для каждой кнопки.Проблема в том, что когда я нажимаю кнопку, результат ранее нажатой кнопки печатается на TextView
.
Мой код
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var mTextView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
mTextView.text = ""
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func showDialogOnClick(_ sender: UIButton) {
//Creating UIAlert, giving its title and message, setting style(alert OR alertSheet)
let mDialog = UIAlertController(title: "Title", message: "This is the message" , preferredStyle: .actionSheet)
//add actions/buttons to alert
mDialog.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: {(action) in
print("Cancel")
self.mTextView.text = "Cancel"
}))
mDialog.addAction(UIAlertAction(title: "Default", style: .default, handler: {(action) in
print("Default")
self.mTextView.text = "Default"
}))
mDialog.addAction(UIAlertAction(title: "Destructive", style: .destructive, handler: {(action) in
print("Destructive")
self.mTextView.text = "Destructive"
}))
self.present(mDialog, animated: true)
}
}