Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding input accessory view to UITextField while keyboard is visible

I would like to add an input accessory view to a UITextField while it is the first responder, i.e. showing the keyboard. Apparently, assigning a UIView to the inputAccessoryView property in this state doesn't display this view. I have to first dismiss the keyboard and re-select the UITextField.

Is there a way to add an input accessory view without dismissing and re-selecting?

like image 266
fabian789 Avatar asked May 10 '11 16:05

fabian789


3 Answers

You can use reloadInputViews on the textView to do that

(I know this is an old post but might help to others)

like image 118
Zeev Vax Avatar answered Nov 03 '22 18:11

Zeev Vax


If possible only assign the inputAccessoryView once. If you need it to be customized, and can only determine how very late just before becoming the first responder, then I would still only assign it once. But customize the subviews of the inputAccessoryView in the UITextFieldDelegate method textFieldShouldBeginEditing:. Like so:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    [self setupInputAccessoryViewForTextField:textField];
    return YES;
}
like image 25
PeyloW Avatar answered Nov 03 '22 20:11

PeyloW


I just wanted an input accessory view added/removed dynamically. I ended up simply doing this:

[self.responceTextView resignFirstResponder];
self.responceTextView.inputAccessoryView = keyBoardToolbar;
[self.responceTextView becomeFirstResponder];
like image 3
Darren Avatar answered Nov 03 '22 20:11

Darren