以编程方式为 UITextField 创建 .touchUpInside 事件

programmatically create .touchUpInside event for UITextField

使用 UITextField 添加了一个 pickerView。

我正在尝试以编程方式触发 pickerView。

    func myTypeDetector (textfield: UITextField) {
    typeLabel.delegate = self
    self.setType(textField: typeLabel)
}

override func viewDidLoad() {
    super.viewDidLoad()
    typeLabel.addTarget(self, action: #selector(NewSpeciesVC.myTypeDetector(textfield:)), for: UIControlEvents.touchUpInside)
}

我已经找到如何通过 UIButton 执行此操作

self.typeLabel.sendActions(for: .touchUpInside)

但是,这不适用于 UITextField。

我想以编程方式使用 TextField 创建事件,或使用 UIButton 创建 PickerView 事件。

有什么建议吗?

我需要做同样的事情并想通了:

self.typelabel.becomeFirstResponder()