Error adding input type to iOS 8 text box

I had a problem when I add a custom input view to my application on iOS 8. This works fine on iOS 7, but when switching to iOS 8 everything fails.

This is the stack trace:

2014-06-03 21:23:54.237 MyApp[1910:47245] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x1103f9d40> should have parent view controller:<StopChooser: 0x11083e200> but requested parent is:<UIInputWindowController: 0x110858800>' *** First throw call stack: ( 0 CoreFoundation 0x00000001042eee35 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000103b919a0 objc_exception_throw + 45 2 CoreFoundation 0x00000001042eed6d +[NSException raise:format:] + 205 3 UIKit 0x00000001023d94cd -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 184 4 UIKit 0x0000000102977a2b -[UIInputWindowController changeToInputViewSet:] + 416 5 UIKit 0x0000000102973f56 -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 185 6 UIKit 0x000000010297826a -[UIInputWindowController setInputViewSet:] + 526 7 UIKit 0x0000000102973c97 -[UIInputWindowController performOperations:withAnimationStyle:] + 50 8 UIKit 0x00000001027559bb -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1054 9 UIKit 0x0000000102422afd -[UIResponder becomeFirstResponder] + 468 10 UIKit 0x00000001023235d3 -[UIView(Hierarchy) becomeFirstResponder] + 99 11 UIKit 0x00000001029cdbfb -[UITextField becomeFirstResponder] + 51 12 UIKit 0x0000000102655d61 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 177 lib: terminating with uncaught exception of type NSException (lldb) 

The relevant part is some of the best lines. Can someone explain this? All I call is myTextview.inputView = keyboard ; A keyboard is a UIView created in a storyboard and linked through an IBOutlet.

+51
ios objective-c ios8
Jun 04 '14 at 4:38
source share
12 answers

I have encountered this problem before.

Problem :

  • You must make sure that the view you assign to inputView or inputAccessoryView does not belong to the parent view. When you create these views from xib inside the ViewController, by default they are set as subviews of the supervisor.

Tips for solving :

  • Use the removeFromSuperview method in the view you assign to inputView or inputAccessoryView
+92
Sep 17 '14 at 4:23
source share

Just before becomeFirstResponder remove the View that you use to enter from the supervisor:

 mTextField.inputView = mInputVeiw; [mInputVeiw removeFromSuperview]; [mTextField becomeFirstResponder]; 

Hope this helps.

+16
Sep 22 '14 at 6:58
source share

I get it. I'm not sure what the problem was before, but instead of binding the UIView in the interface constructor, I created the UIView program code UIView and it worked fine.

+2
Jun 11 '14 at 22:35
source share

I found a solution creating a UIView programmatically (as suggested by Milo), but it crashes when it is used as @property. In my case, I needed to instantiate a UIPickerView in viewDidLoad and get a UITextView inputView view. When I need to remove pickerView, I get it like this:

 UIPickerView *picker = (UIPickerView *)self.myTextField.inputView; 
+1
Sep 05 '14 at 16:31
source share

Yes, Tuyen Nguyen's solution did not work for me. What worked for me in iOS8 / Xcode 6 to set inputAccessoryView not to remove FromSuperview BUT

 [[UIApplication sharedApplication].keyWindow addSubview:**MyViewToBeTheUIAccessoryView**]; 

I hope this helps someone.

+1
Sep 30 '14 at 13:00
source share

You must make sure that the view you assign to inputView or inputAccessoryView does not belong to any parent view.

This error is particularly annoying since any β€œinput view” created in the storyboard (and thus added to the VC view ) cannot be set as inputView or inputAccessoryView without causing this failure.

If the input view is not added to the VC view , the input view will not be available for visual editing in the interface builder layout. It is displayed only in the left panel of the storyboard.

How to connect the Xcode Storyboard "Simulated Metrics" toolbar to the actual IBUutlet UIToolbar?

I would rather make an IB connection to inputAccessoryView right in the storyboard. It causes this crash. The 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, and then immediately assign inputAccessoryView . Not sure if I will eventually use this.

 - (void) viewDidLoad { // ... [self.keybordView removeFromSuperview]; self.inputAccessoryView = self.keybordView; } 
+1
May 28 '15 at 1:34
source share

I had the same problem when I was trying to configure my UIDatePicker in a UITextField

 - (void)setupViews { ... dobField.inputView = aDatePicker; // Here was the problem ... } 

My solution, I just β€œassign” and β€œrun” my datePicker in ViewDidLoad

 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ... aDatePicker = [[UIDatePicker alloc] init]; // My solution ... } 
0
Sep 30 '14 at 14:33
source share

The removeFromSuperView call in viewDidLoad does not seem to work properly in modules. I ended up setting the hidden view and then removing it from superView in viewDidAppear .

0
Mar 08 '15 at 17:30
source share

Most of the answers I was related to code changes. I found out that the removal of the output in the UIView inside the main view is fixed. stack overflow

0
Oct. 14 '16 at 7:23
source share

My solution for this problem was to add the view to the inputView, but not add the view controller to the parent.

0
Nov 17 '16 at 12:43
source share

I had the same error when I returned any view from the storyboard as inputAccessoryView . I installed it using childViewController. See my answer here .

0
May 27 '17 at 16:44
source share

My problem was that I called the view with inputAccessoryView text box ...

 @property (weak, nonatomic) IBOutlet CustomView *inputAccessoryView; 

Mistake:

 Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x7fed7063a1a0> should have parent view controller:<MyViewController: 0x7fed70606f00> but requested parent is:<UIInputWindowController: 0x7fed710cde00>' 

Decision:

Check naming; do not override if not necessary.

0
Jun 11 '17 at 22:18
source share



All Articles