转载自: http://ask.csdn.net/questions/3386
用我方法:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(textFieldTextDidChangeOneCI:)
name:UITextFieldTextDidChangeNotification
object:textfield];
}
然后将你的方法改为:
-(void)textFieldTextDidChangeOneCI:(NSNotification *)notification
{
UITextField *textfield=[notification object];
NSLog(@"%@",textfield.text);
}
本来用它的代理方法:(但发现这样始终不行,因为self.contentField.text 这个值始终比输入框的实际文字少一位,用上边的方法搞定)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSLog(@"字符: %@--%@--%d",self.contentField.text,string,range.location);
if (range.location == 11) {
[[NSNotificationCenter defaultCenter] postNotificationName:GNNotifiIsShowPassTextField object:textField.text userInfo:nil];
return NO; // return NO to not change text
}
return YES;
}