below you\'ll find my .h & .m files for my primary viewcontroller.
I have 3 questions.
1.) Because I have multiple uitextfields, do I have to set each with
Resigning the textField: All your textField.delegate should be set as ViewController's object. And then implement the below delegate method.
-(BOOL) textFieldShouldReturn: (UITextField *) textField {
[textField resignFirstResponder];
return YES;
}
To dismiss Keyboard on tap of the View: Add a Tap gesture to your ViewController.view as follows:
//declare a property to store your current responder
@property (nonatomic, assign) id currentResponder;
//in viewDidLoad:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resignOnTap:)];
[singleTap setNumberOfTapsRequired:1];
[singleTap setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:singleTap];
[singleTap release];
//Implement the below delegate method:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
self.currentResponder = textField;
}
//Implement resignOnTap:
- (void)resignOnTap:(id)iSender {
[self.currentResponder resignFirstResponder];
}
// was missing ; after the call --> [self.currentResponder resignFirstResponder]
// also in textFieldDidEndEditing set self.currentResponder = nil;