I study iOS SDK using this book and in 4 Chapter, when it tells you how to hide number pad with background tap I have a problem. I do that author says but nothing happened. How I can do this?
What book’s author says:
1)Create new method backgroundTap in ViewController.h
- (IBAction)touchBackground:(id)sender;
2)Add method in ViewController.m
-(void)touchBackground:(id)sender{
[nameField resignFirstResponder];
[numberField resignFirstResponder];}
3)Change class identity of View object in Interface Builder(as I understand in Xcode 4 its Control) from UIView to UIControl
4)Connect TouchDown method in events list with File’s Owner and check method backgroundTap.
This is my code samples
P.S. I’m sorry for my English, I translated all information from the book to english because I have russian translate.
I think you might make this simpler by just implementing a method like this:
make the background view
UIControlinstead ofUIViewin interface builder and hook the touches up event to this method.Have a look at this small example project. I have done exactly this in the
secondViewControllerwhere touching the background dismissed the keyboard. You can also see how I have changed the background to aUIControlinsecondViewController.xib