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

当我在 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

https://stackoverflow.com/questions/24029113/

相关文章:

ios - 每次 Xcode 重新启动时 View 错位

iphone - 带有 "Go"按钮而不是返回的 iOS 键盘

iphone - 重复符号问题

ios - Xcode 如何加载主 Storyboard ?

iphone - 在 NSUserDefaults 中存储值是否有任何限制?

ios - 是否在 iOS SDK 中的任何位置定义了 HTTP 状态代码?

objective-c - Foo 类在 MyApp 和 MyAppTestCase 中都实现了。将

ios - 在代码生成的 UIView 上绘制 UIBezierPath

ios - 无法从其 DataSource 获取单元格

ios - NSNotificationCenter 的帖子导致 "EXC_BAD_ACCESS"异