我用三个操作按钮创建了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)
}
}
答案 0 :(得分:2)
我认为可能的问题是,您正在模拟器中对此进行测试,并且计算机的图形配置较低,当我在旧的Mac mini中测试代码时,也会发生同样的事情。您可以做两件事:-< / p>
让我知道我是否正确。