Adding tool bar on top of the uikeyboard

user198725878 picture user198725878 · Jan 25, 2012 · Viewed 20.3k times · Source

I have a toolbar and i would like to place it on top of the keyboard.

In the keyboardwillshow notification, i tried to add toolbar to the keyboard but no luck, i cant add

Please let me know

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard;
    for(int i = 0; i < [tempWindow.subviews count]; i++)
    {
        //Get a reference of the current view 
        keyboard = [tempWindow.subviews objectAtIndex:i];

        //Check to see if the description of the view we have referenced is "UIKeyboard" if so then we found
        //the keyboard view that we were looking for
        if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
        {
            [keyboard addSubview:myToolbar];
        }
    }

Answer

vikingosegundo picture vikingosegundo · Jan 25, 2012

I think, you want an inputAccessoryView.

Basically, you create a view and set it as a text field's or text view's input accessory view.

[textField setInputAccessoryView:inputAccessoryView];