我正在尝试实现一个可重用的UITextFieldDelegate
类如下:
class CustomTextFieldDelegate : NSObject, UITextFieldDelegate
所有委托协议方法均已正确实现。
In the controller
,我分配delegate
to the UITextField
textField.delegate = CustomTextFieldDelegate()
问题是没有调用任何委托函数。但是,当我从控制器实现委托协议时,一切正常
class CustomTableViewController: UITableViewController, UITextFieldDelegate
有什么想法吗?
如果您想在整个项目中重用 CustomTextFieldDelegate,则应该使用 Singleton 实例;
textField.delegate = CustomTextFieldDelegate.sharedInstance
和班级的变化
class CustomTextFieldDelegate : NSObject, UITextFieldDelegate {
static let sharedInstance:CustomTextFieldDelegate = CustomTextFieldDelegate();
func textFieldDidBeginEditing(textField: UITextField) {
NSLog("textFieldDidBeginEditing ...");
}
//... other methods
} //F.E.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)