Simple Silver Challenge Solution


Not the best solution, but pretty simple. The only problem is that the ‘Done’ button doesn’t disappear after the keyboard is dismissed. I’ll probably continue in the book and come back to that one later.

Added to BNRDetailViewController.m:

// Silver Challenge - Displays 'Done' button when keypad is active
- (IBAction)showButton:(id)sender
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:nil action:@selector(resignFirstResponder)];
    self.navigationItem.rightBarButtonItem = doneButton;

This is connected to the Editing Did Begin event, accessible under Sent Events if you cntrl-click the text field.

Edit: A much better way of doing this is revealed in the next chapter.