Error when adding input view to textfield iOS 8
Just before becomeFirstResponder
remove the View you use for input from the superview :
mTextField.inputView = mInputVeiw;
[mInputVeiw removeFromSuperview];
[mTextField becomeFirstResponder];
Hope it helps.
I encountered this problem before.
Problem:
- You have to ensure that the view you will assign to
inputView
orinputAccessoryView
doesn't belong to any parent view. When you create these views from a xib inside a ViewController, by default they are set as subviews of a superview.
Solution Tips:
- Use the method
removeFromSuperview
on the view you will assign toinputView
orinputAccessoryView
You have to ensure that the view you will assign to
inputView
orinputAccessoryView
don't belong to any parent view.
This error is especially annoying as any "input view" created in a storyboard (and thus added to the VC's view
) cannot be set as the inputView
or inputAccessoryView
without causing this crash.
If the input view is not added to the VC's view
, the input view will not be available for visual editing in the Interface Builder Storyboard. It's only visible in the Storyboard's left pane.
How to connect Xcode Storyboard's "Simulated Metrics" toolbar to an actual IBOutlet UIToolbar?
I'd prefer to make an IB Connection to the inputAccessoryView
directly in the Storyboard. That causes this crash. A solution I found is to make a secondary IBOutlet connected to the view in the Storyboard, then in viewDidLoad
remove it from the super view then immediately assign to inputAccessoryView
. Not sure if I'll end up using this.
- (void)viewDidLoad {
// ...
[self.keybordView removeFromSuperview];
self.inputAccessoryView = self.keybordView;
}