首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将输入视图添加到textfield iOS 8时出错

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

Stack Overflow用户
提问于 2014-06-04 04:38:20
回答 12查看 28.1K关注 0票数 67

当我在iOS 8上为我的应用程序添加一个自定义输入视图时,我遇到了一个问题。这在iOS 7上非常好,但是当切换到iOS 8时,一切都失败了。

这是堆栈跟踪:

代码语言:javascript
复制
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;键盘是在故事板中创建并通过IBOutlet链接的UIView。

EN

回答 12

Stack Overflow用户

回答已采纳

发布于 2014-09-17 04:23:10

我以前遇到过这个问题。

问题

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

解决方案提示

  • 在将分配给inputViewinputAccessoryView的视图上使用方法inputAccessoryView
票数 117
EN

Stack Overflow用户

发布于 2014-09-22 06:58:06

becomeFirstResponder删除从superview中输入的视图之前:

代码语言:javascript
复制
mTextField.inputView = mInputVeiw;
[mInputVeiw removeFromSuperview];
[mTextField becomeFirstResponder];

希望能帮上忙。

票数 20
EN

Stack Overflow用户

发布于 2015-05-28 01:34:58

您必须确保分配给inputViewinputAccessoryView的视图不属于任何父视图。

这个错误特别恼人,因为在故事板中创建的任何“输入视图”(因此添加到VC的view中)都不能被设置为inputViewinputAccessoryView,而不会导致此崩溃。

如果未将输入视图添加到VC的view中,则无法在中对输入视图进行可视化编辑。只有在故事板的左窗格中才能看到。

How to connect Xcode Storyboard's "Simulated Metrics" toolbar to an actual IBOutlet UIToolbar?

我更愿意在故事板中直接连接到inputAccessoryView。导致这次坠机。我找到的一个解决方案是使第二个IBOutlet连接到Storyboard中的视图,然后在viewDidLoad中将其从超级视图中删除,然后立即分配给inputAccessoryView。不知道我会不会用这个。

代码语言:javascript
复制
- (void)viewDidLoad {

    // ...

    [self.keybordView removeFromSuperview];
    self.inputAccessoryView = self.keybordView;
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24029113

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档