Iphone UITextFieldTextDidChangeNotification中的文本
我有一个带有此通知的UITextField:Iphone UITextFieldTextDidChangeNotification中的文本,iphone,objective-c,uitextfield,nsnotificationcenter,nsnotification,Iphone,Objective C,Uitextfield,Nsnotificationcenter,Nsnotification,我有一个带有此通知的UITextField: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:@"UITextFieldTextDidChangeNotification" object:_searchTextField]; - (void)textFieldDidChange :(NSNotification *)notif {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:@"UITextFieldTextDidChangeNotification" object:_searchTextField];
- (void)textFieldDidChange :(NSNotification *)notif
{
//
}
当我输入r
NSConcreteNotification 0x193c20 {name = UITextFieldTextDidChangeNotification; object = <UITextField: 0x15a980; frame = (20 20; 280 31); text = 'r'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x15aad0>>}
NSConcreteNotification 0x193c20{name=UITextFieldTextDidChangeNotification;object=}
如何从notif对象中获取文本
r
?通知的对象
属性存储其文本已更改的文本字段,因此notif.object.text
将包含文本“r”。它给出了一个错误-在类型为'id'do[(UITextField*)notif.object text]的对象上找不到属性'text'
是的,所以我必须:UITextField*txt=(UITextField*)notif.object;NSlog(@“%@”,txt.text);您应该使用常量UITextFieldTextDidChangeNotification(在UITextField.h中声明),而不是将自己的NSString作为“name”参数传递