[英]set text to TextView on action button of AlerView click [iOS, Swift]
我創建UIAlertController
具有三個操作按鈕的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)
}
}
我認為可能的問題是,您正在模擬器中對此進行測試,並且計算機的圖形配置較低,當我在舊的Mac mini中測試代碼時,也會發生同樣的事情。您可以做兩件事:-
讓我知道我是否正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.