簡體   English   中英

在AlerView的操作按鈕上將文本設置為TextView,然后單擊[iOS,Swift]

[英]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中測試代碼時,也會發生同樣的事情。您可以做兩件事:-

  1. 在物理設備中測試代碼
  2. 嘗試將模擬器中的應用程序最小化,然后返回該應用程序,您將看到效果,或者來回更改視圖以查看效果。

讓我知道我是否正確。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM