Adding input accessory view to UITextField while keyboard is visible
Solution 1
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;
}
Solution 2
You can use reloadInputViews on the textView to do that
(I know this is an old post but might help to others)
Solution 3
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];
fabian789
Doing mainly iOS programming, but also some Python, Bash, Java, C++ and other stuff!
Updated on July 09, 2022Comments
-
fabian789 almost 2 years
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 aUIView
to theinputAccessoryView
property in this state doesn't display this view. I have to first dismiss the keyboard and re-select theUITextField
.Is there a way to add an input accessory view without dismissing and re-selecting?
-
manmal over 11 yearsthat messes up keyboard behavior.
-
Darren over 11 yearsNot for me it doesn't. Maybe you should start a question with the code your using.
-
manmal over 11 yearsMy problem is not solvable at all without private APIs (I found a workaround though). But, your code let my keyboard jerk around when in undocked mode. That might be related to textview listeners, but still - it's a hack.
-
Varrry almost 4 yearsthis should be checked answer