Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:50:17+00:00 2026-06-09T20:50:17+00:00

I added a toolbar with TextField in NavigationController by – (void)viewDidLoad { // …

  • 0

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!!

Screenshot 1 - Before

Screenshot 2 - After

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:50:18+00:00Added an answer on June 9, 2026 at 8:50 pm

    Best solution is to set inputAccessoryView to UITextField like this :

    #pragma mark - UITextFieldDelegate
    
    -(void)textFieldDidBeginEditing:(UITextField *)textField{
       // Call the createInputAccessoryView method we created earlier.
       // By doing that we will prepare the inputAccView.
    
       UIView *inputAccView = [self createInputAccessoryView];
          // Now add the view as an input accessory view to the selected textfield.
       [textField setInputAccessoryView:inputAccView];  
    }
    

    -(UIView *)createInputAccessoryView{
      // Create the view that will play the part of the input accessory view.
      // Note that the frame width (third value in the CGRectMake method)
      // should change accordingly in landscape orientation. But we don’t care
      // about that now.
      UIView *inputAccView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 40.0)];
      // Set the view’s background color. We’ ll set it here to gray. Use any color you want.
      [inputAccView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.20f]];
      // We can play a little with transparency as well using the Alpha property. Normally
      // you can leave it unchanged.
      [inputAccView setAlpha: 0.8];
    
      UIButton *btnDone = [UIButton buttonWithType:UIButtonTypeCustom];
      [btnDone setFrame:CGRectMake(240.0, 6.0f, 70.0f, 28.0f)];
      [btnDone setTitle:@"Done" forState:UIControlStateNormal];
      [btnDone setBackgroundColor:[UIColor blackColor]];
      [btnDone.layer setCornerRadius:6.0f];
      [btnDone setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
      [btnDone addTarget:self action:@selector(btnDoneForKeyboardAction:) forControlEvents:UIControlEventTouchUpInside];
      // Now that our buttons are ready we just have to add them to our view.
      [inputAccView addSubview:btnDone];
    
      return inputAccView;
    }
    

    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:

    - (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    }
    

    In response to the keyboard appearing, we can animate the toolbar up from the bottom of the screen:

    - (void)keyboardWillShow:(NSNotification *)notification {
       //set your toolbar frame here for upper side
    }
    

    When the keyboard is dismissed, we do just the opposite:

    - (void)keyboardWillHide:(NSNotification *)notification {
       //set your toolbar frame here for down side
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I added UIWindow and its toolbar like: self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]
I added a toolBar with this code: - (void)viewWillAppear:(BOOL)animated { UIBarButtonItem *yesterday = [[UIBarButtonItem
I added a toolbar for an ipad application programatically. UIToolbar *drawToolBar = [[UIToolbar alloc]
I've added a toolbar to my grid I'm not able to bind the event
I've recently added the wibiya toolbar to my site. Since doing that, my jquery
I have added a toolbar menu for my macro, so I can just press
I made a custom toolbar and added a UITabBarItem. Now I want to load
I've added a button to a lower toolbar like this: UIImage *locationImage = [UIImage
How can a button be added to a navigation toolbar in an application which
I added toolbar to on screen of navigation based application using the following code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.