I added a toolbar with TextField in NavigationController by
- (void)viewDidLoad
{
// ...
[self.navigationController setToolbarHidden:NO animated:YES];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 2, 240, 36)];
textField.placeholder = @"Leave your comment here...";
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
UIBarButtonItem *commentTextFieldBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:textField];
self.toolbarItems = [NSArray arrayWithObject:commentTextFieldBarButtonItem];
}
When user click on the TextField, I hope the toolbar move up with keyboard.
I tried this method. The toolbar moved up, but became empty. Am I doing something wrong? Please help me, thanks!!


Best solution is to set
inputAccessoryViewtoUITextFieldlike this :Another solution:
When the view controller appears, we want to be notified of keyboard events so that we can show the toolbar in response to the keyboard appearing and disappearing:
In response to the keyboard appearing, we can animate the toolbar up from the bottom of the screen:
When the keyboard is dismissed, we do just the opposite: