【发布时间】:2013-03-14 11:00:52
【问题描述】:
我有一个扩展 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
【问题讨论】:
标签: ios objective-c uitextfield