我有一个扩展UITextfield的类。我也有相同的类设置为它自己的委托,所以当选择文本字段时,我可以更改背景颜色。一旦我选择了文本字段并输入了几个字母,该应用就会锁定并崩溃。为什么UITextField在将自己设置为委托时锁定
这里是我的.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