通过给textField添加监听事件可以获取到当前输入的文本内容
[textField addTarget:self action:@selector(getText:) forControlEvents:UIControlEventEditingChanged];
代理方法
//将要开始编辑的时候
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow editing.
//已经开始编辑的时候
- (void)textFieldDidBeginEditing:(UITextField *)textField; // became first responder
//将要结束编辑的时候
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;
//已经结束编辑的时候
- (void)textFieldDidEndEditing:(UITextField *)textField; // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called
//这里的textField.text是获取的是上一次编辑的内容
//string可以获取本次输入的内容(只能检测英文和数字)(可以用来控制输入)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; // return NO to not change text
//将要开始清除
- (BOOL)textFieldShouldClear:(UITextField *)textField;
//将要开始返回
- (BOOL)textFieldShouldReturn:(UITextField *)textField;