我正在尝试实现一个可重用的UITextFieldDelegate类,如下所示:
class CustomTextFieldDelegate : NSObject, UITextFieldDelegate所有委托协议方法都被正确地实现。
在controller中,我将delegate分配给UITextField
textField.delegate = CustomTextFieldDelegate()问题是没有调用任何委托函数。但是,当我实现来自控制器的委托协议时,事情会很好。
class CustomTableViewController: UITableViewController, UITextFieldDelegate有什么好主意吗?
发布于 2015-10-08 04:51:56
如果您希望通过项目重用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.https://stackoverflow.com/questions/33006082
复制相似问题