我正在为我的文本字段使用SkyFloatingTextField
框架(它是UITextField
的子类),并且我还想使用AnyFormatKit
格式化程序作为电话号码掩码。因为它使用TextInput
委托,所以我创建了一个自定义类来实现TextInput
委托,但是我遇到了错误。
未在super.init调用中初始化属性'self.textInputDelegates'
class customTextField: SkyFloatingLabelTextField, TextInput{
var content: String?
var attributedContent: NSAttributedString?
var textInputDelegates: MulticastDelegate<TextInputDelegate>
override init(frame: CGRect) {
super.init(frame: frame)
}
init(){
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
textInputDelegates.add(delegate: self.inputDelegate as! TextInputDelegate)
}
}
答案 0 :(得分:0)
You can implement delegate methods of a textfield subclass by making use of a supportive class as below.
class TextFieldSupport: NSObject, TextInputDelegate {
//Supporting class for your textfield delegate
var tfDelegate: UITextFieldDelegate?
//MARK: Implement TextInputDelegate Delegate Methods here.
}
class CustomTextField: SkyFloatingLabelTextField {
//SkyFloatingLabelTextField Subclass
var content: String?
var attributedContent: NSAttributedString?
var textInputDelegates: TextFieldSupport = TextFieldSupport.init()
override init(frame: CGRect) {
super.init(frame: frame)
}
init(){
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
textInputDelegates.add(delegate: self.inputDelegate as! TextInputDelegate)
}
override var delegate: UITextFieldDelegate? {
didSet {
textInputDelegates.tfDelegate = delegate
super.delegate = support
}
}
}