ios - 将输入 View 添加到文本字段 iOS 8 时出错

标签 ios objective-c ios8

当我在 iOS 8 上向我的应用程序添加自定义输入 View 时遇到问题。这在 iOS 7 上运行良好,但在切换到 iOS 8 时一切都失败了。

这是堆栈跟踪:

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) 

相关部分是前几行。有人可以解释一下吗?我要调用的是 myTextview.inputView = keyboard;键盘是在 Storyboard 中创建并通过 IBOutlet 链接的 UIView。

最佳答案

我以前遇到过这个问题。

问题:

  • 您必须确保分配给 inputViewinputAccessoryView 的 View 不属于任何父 View 。当您从 ViewController 中的 xib 创建这些 View 时,默认情况下它们被设置为 super View 的 subview 。

解决方案提示:

  • 在您将分配给 inputViewinputAccessoryView
  • 的 View 上使用方法 removeFromSuperview

关于ios - 将输入 View 添加到文本字段 iOS 8 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24029113/

相关文章:

java - 准备开始 CSIS : Java Programming

ios - 使用 deleteRows 后,becomeFirstResponer() 不会将焦点放在 textField

ios - UITextField Action - 改变 SKLabelNode

ios - 在 UILongPressGestureRecognizer 上无法检测到右(按下)按钮?

ios - NSManagedObject setter 给我 [ MyObject setName :]: unrecognized selector sent to instance

ios - MAC Sierra 10.12 使用 xcode 调试 View 层次结构变空,不显示 View

ios - 如何处理退款/取消应用内购买

objective-c - Vfr-Reader 在 assert(range.location != NSNotFound) 上崩溃;

ios - NSDictionary 的第一个元素是 <null> 而不是 1

iphone - 应用程序内购买无法正常工作。它给出 "Can not connect to itunes"