iphone, dismiss keyboard when touching outside of textfield

You'll need to add an UITapGestureRecogniser and assign it to the view, and then call resign first responder on the textfield on it's selector.

The code:

In viewDidLoad

UITapGestureRecognizer*tap =[[UITapGestureRecognizer alloc] 
                                       initWithTarget:self
                                       action:@selector(dismissKeyboard)];

[self.view addGestureRecognizer:tap];

In dismissKeyboard:

-(void)dismissKeyboard {[aTextField resignFirstResponder];}

猜你喜欢

转载自dsr-22.iteye.com/blog/2186501
今日推荐