来自UITextFieldTextDidChangeNotification的文本

时间:2012-03-31 09:41:31

标签: iphone objective-c uitextfield nsnotificationcenter nsnotification

我有一个带有NSNotification的UITextField:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:@"UITextFieldTextDidChangeNotification" object:_searchTextField];

- (void)textFieldDidChange :(NSNotification *)notif 
    {
     //
    }

当我输入r

时,NSLog就是
NSConcreteNotification 0x193c20 {name = UITextFieldTextDidChangeNotification; object = <UITextField: 0x15a980; frame = (20 20; 280 31); text = 'r'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x15aad0>>}

如何从notif对象中获取文本r

1 个答案:

答案 0 :(得分:16)

通知的object属性存储文本已更改的文本字段,因此notif.object.text将包含文本“r”。