我有一個擴展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