gpt4 book ai didi

ios - 未调用自定义 UITextField 委托(delegate)方法 shouldChangeCharactersIn

转载 作者:行者123 更新时间:2023-11-28 23:55:41 29 4
gpt4 key购买 nike

在我的自定义 UITextField 中,textFieldDidBeginEditing()textFieldDidEndEditing() 委托(delegate)方法被调用但是func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> bool

@IBDesignable class CustomUITextField: UITextField, UITextFieldDelegate{

//getting Called
@objc func textFieldDidBeginEditing() {

}

//getting Called
@objc func textFieldDidEndEditing(){

}

//Not getting Called
@objc func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

}

}

我不知道为什么没有接到电话。为此需要做任何额外的工作吗?

提前致谢。

最佳答案

你需要设置委托(delegate)

@IBDesignable class CustomUITextField: UITextField, UITextFieldDelegate{

override init(frame: CGRect) {
super.init(frame: frame)

self.delegate = self
}

required init?(coder aDecoder: NSCoder) {

super.init(coder: aDecoder)

self.delegate = self
}

//getting Called
@objc func textFieldDidBeginEditing() {

print("textFieldDidBeginEditing")
}

//getting Called
@objc func textFieldDidEndEditing(){

print("textFieldDidEndEditing")
}

//Not getting Called
@objc func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

print("shouldChangeCharactersIn")

return true

}

}

关于ios - 未调用自定义 UITextField 委托(delegate)方法 shouldChangeCharactersIn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51284532/

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