Dismissing keyboard when tapping elsewhere


#1

For the Silver Challenge in Chapter 11, I used this to dismiss the number pad:

Implemented in DetailViewController.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [[self view] endEditing:YES];
}

At the end of Chapter 12 we changed our view to a UIControl and implemented a custom method that does the same thing. (Also in DetailViewController.m)

- (IBAction)backgroundTapped:(id)sender
{
    [[self view] endEditing:YES];
}

Is there any real difference between the two methods? Are they both acceptable or would one be more appropriate than the other?


#2

I would like to know if there’s any difference as well. Hopefully someone can highlight the answer.


#3

They are both acceptable. I like to keep touch code out of the controller when I can, though.


#4

joe, i’d love to know what you think is a good solution to the chapter 11 silver challenge. i’ve done all of the challenges up to this point and i’m having a tough time with this one… should i use the accessory view on a custom number pad view?