我有一个扩展 UITextfield 的类。I also have the same class set to be it's own delegate so when the text field is selected I can change the background color. 一旦我选择了文本字段并输入了几个字母,应用程序就会锁定并崩溃。
这是我的 .m 文件的样子
@implementation MyTextField
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.delegate = self;
}
return self;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"run did begine editing");
[self setBackgroundColor:[UIColor colorWithRed:0.204 green:0.239 blue:0.275 alpha:0.25]];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSLog(@"run did end editing");
[self setBackgroundColor:[UIColor clearColor]];
}
这是.h
@interface MyTextField : UITextField <UITextFieldDelegate>
@end