1、viewDidLoad的时候注册监听器
// 注册监听器
[self registerForKeyboardNotifications];
2、利用UIKeyboardDidShowNotification通知调用 [textField selectAll:self]方法:
#pragma mark - registerForKeyboardNotifications
// UITextField弹出键盘之后自动选中已有的文字
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification
object:nil];
}
- (void)keyboardWasShown:(NSNotification*) notification
{
[textField selectAll:self];
}