使用 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()
关于swift - 以编程方式为 UITextField 创建 .touchUpInside 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46375700/