Check for changes in UITextField

2020-02-07 12:19发布

I'm attempting to make an app that checks the text in a UITextField and does something in response to what is written in it. I could possibly have the user type their input and then press a button. I want to be able to check the text field constantly without the application becoming unresponsive.

1条回答
\"骚年 ilove
2楼-- · 2020-02-07 12:45

What you have to do is to attach an IBAction to your UITextField Sent Events Editing Changed:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var strLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    @IBAction func editingChanged(sender: UITextField) {
        strLabel.text = sender.text
    }
}

enter image description here

enter image description here

查看更多
登录 后发表回答