iosuitextfielduikeyboard

Adding UITextField above Keyboard


I found this link how to create tool bar above keyboard. But I don't use any textfield that I need to tap and show keyboard. My idea is press on "Leave comment" button and then keyboard with a text field will be appeared.

So in the link I've attached they seems use inputAccessoryView of text field you interact with. But in my case I don't have any text field.

So first of all I need to toggle keyboard without text field and then show keyboard with a textfield like a bar above keyboard. How can I make it?


Solution

  • Hello you need to put your UITextfield outside the View, like this:

    enter image description here

    ViewController.h

    @property (strong, nonatomic) IBOutlet UITextField *_myTextField;
    

    ViewController.m

    UITextField *t = [UITextField new];
    [self.view addSubview:t];
    [t becomeFirstResponder];
    t.inputAccessoryView = _myTextField;
    

    see the result: enter image description here