gpt4 book ai didi

ios - 以编程方式从 inputAccessoryView 执行 textFieldShouldReturn

转载 作者:行者123 更新时间:2023-11-30 13:44:33 26 4
gpt4 key购买 nike

从输入附件 View 中以编程方式执行(模拟)func textFieldShouldReturn(textField: UITextField) -> Bool 函数的方式是什么。

MyCustomInputView 有“完成”按钮。我希望当按下 DONE 按钮时,将为 MyTextField 委托(delegate)触发 func textFieldShouldReturn(textField: UITextField) -> Bool 。有什么方法可以实现呢?

class MyTextField: UITextField {

func setup() {
let myCustomInputView = MyCustomInputView()
self.inputAccessoryView = myCustomInputView
}
}

最佳答案

我扩展了 MyCustomInputView 将具有 UITextField 的功能。

class MyCustomInputView: UIView {
var textField: UITextField?

@IBAction func didClickReturnButton(sender: UIButton) {
if let textField = textField, let textFieldDelegate = textField?.delegate {
if textFieldDelegate.textFieldShouldReturn!(textField) {
textField.endEditing(true)
}
}
}
}

关于ios - 以编程方式从 inputAccessoryView 执行 textFieldShouldReturn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35133520/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com