为了账号安全,请及时绑定邮箱和手机立即绑定

将输入视图添加到textfield iOS 8时出错

将输入视图添加到textfield iOS 8时出错

眼眸繁星 2019-11-13 15:32:28
我在iOS 8上向我的应用程序添加自定义输入视图时遇到问题。在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    + 177lib: terminating with uncaught exception of type NSException    (lldb) 相关部分是前几行。有人可以解释吗?所有我打电话是myTextview.inputView = keyboard; 键盘是在情节提要中创建并通过IBOutlet链接的UIView。
查看完整描述

3 回答

?
慕丝7291255

TA贡献1859条经验 获得超6个赞

我以前遇到过这个问题。

问题

  • 您必须确保将分配给该视图inputViewinputAccessoryView不属于任何父视图。当您从ViewController中的xib创建这些视图时,默认情况下会将它们设置为超级视图的子视图。

解决方案提示

  • removeFromSuperview在您要分配给视图的方法上使用inputViewinputAccessoryView


查看完整回答
反对 回复 2019-11-13
?
守着星空守着你

TA贡献1799条经验 获得超8个赞

就在becomeFirstResponder从超级视图中删除用于输入的View 之前:


mTextField.inputView = mInputVeiw;

[mInputVeiw removeFromSuperview];

[mTextField becomeFirstResponder];

希望能帮助到你。


查看完整回答
反对 回复 2019-11-13
?
蛊毒传说

TA贡献1895条经验 获得超3个赞

您必须确保将分配给该视图inputView或inputAccessoryView不属于任何父视图。


由于在情节提要中创建的任何“输入视图”(因此已添加到VC中view)都不能设置为inputView或inputAccessoryView不导致崩溃,因此此错误尤其令人讨厌。


如果输入视图未添加到VC view,则输入视图将无法在Interface Builder故事板中进行可视化编辑。仅在情节提要的左窗格中可见。


如何将Xcode故事板的“模拟指标”工具栏连接到实际的IBOutlet UIToolbar?


我希望inputAccessoryView直接在情节提要中建立IB连接。这会导致崩溃。我发现的解决方案是使第二个IBOutlet连接到情节提要中的视图,然后viewDidLoad将其从超级视图中删除,然后立即分配给inputAccessoryView。不知道我是否最终会使用它。


- (void)viewDidLoad {


    // ...


    [self.keybordView removeFromSuperview];

    self.inputAccessoryView = self.keybordView;

}


查看完整回答
反对 回复 2019-11-13
  • 3 回答
  • 0 关注
  • 797 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信