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

标签 swift uipickerview

使用 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/

相关文章:

ios - StackView 中 UIPickerView 的问题

ios - 如何从另一个 UIPickerView 更改 UIPickerView 的字符串?

ios - UIImage 不保存到磁盘

ios - 我如何识别不同的pickerView?

swift - 扩展协议(protocol),其中 Self : Generic Type in Swift (Requires Arguments In <. ..>)

ios - 需要从父类(super class)属性访问子类属性

ios - 使用 AlertController 强制更新应用程序

ios - 3 组件UIPickerView 制作3位数值

ios - 包含另一个 TableView 的 Tableview 单元格的动态高度

swift - 没有从 GameViewController 菜单移动到 GameScene Swift