Milo Milo - 16 days ago 10
iOS Question

Error when adding input view to textfield iOS 8

I'm having an issue when I add a custom input view to my app on iOS 8. This was working perfectly 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 being the top few lines. Can someone explain this? All I'm calling is
myTextview.inputView = keyboard
; Keyboard being a UIView created in the storyboard and linked via IBOutlet.

Answer

I encountered this problem before.

Problem:

  • You have to ensure that the view you will assign to inputView or inputAccessoryView 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 to inputView or inputAccessoryView
Comments