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.
当我在ios8上添加自定义输入视图到我的应用程序时,我有一个问题。这在iOS 7上运行得很好,但当切换到iOS 8时,一切都失败了。
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.
相关的部分是前几行。有人能解释一下这个吗?我调用的是myTextview。视图=键盘;另键盘是在故事板中创建的UIView,通过IBOutlet链接。
12 个解决方案
#1
100
I encountered this problem before.
我以前遇到过这个问题。
Problem:
问题:
- You have to ensure that the view you will assign to
inputView
orinputAccessoryView
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. - 您必须确保将分配给inputView或inputAccessoryView的视图不属于任何父视图。当您在一个视图控制器中从一个xib创建这些视图时,默认情况下它们被设置为一个超视图的子视图。
Solution Tips:
解决方案建议:
- Use the method
removeFromSuperview
on the view you will assign toinputView
orinputAccessoryView
- 在您将分配给inputView或inputAccessoryView的视图上使用removeFromSuperview方法。
#2
17
Just before becomeFirstResponder
remove the View you use for input from the superview :
在成为firstresponder之前,要删除从超级视图中输入的视图:
mTextField.inputView = mInputVeiw;
[mInputVeiw removeFromSuperview];
[mTextField becomeFirstResponder];
Hope it helps.
希望它可以帮助。
#3
2
I figured it out. I'm not sure what the issue was before but instead of linking a UIView
in interface builder, I instead created a UIView
programmatically and it worked fine.
我想出来。我不知道之前的问题是什么,但是我没有在接口构建器中链接一个UIView,而是通过编程的方式创建了一个UIView,而且效果很好。
#4
1
Yeah, the Tuyen Nguyen solution did not work for me. What worked for me in iOS8 / XCode 6 for setting an inputAccessoryView was not to removeFromSuperview BUT to
是啊,阮先生的办法对我不起作用。我在iOS8 / XCode 6中为我设置了一个inputAccessoryView,而不是从superview中删除,而是!
[[UIApplication sharedApplication].keyWindow addSubview:**MyViewToBeTheUIAccessoryView**];
I hope this helps someone.
我希望这能帮助别人。
#5
1
I found the solution creating the UIView programmatically (Like suggested by Milo), but it crashes when its used like a @property. In my case, I needed to create the UIPickerView instance in viewDidLoad and assing to UITextView inputView. When I need to acess the pickerView I get it like this
我找到了以编程方式创建UIView的解决方案(就像Milo所建议的那样),但是当它使用的是@property时就崩溃了。在我的例子中,我需要在viewDidLoad中创建UIPickerView实例,并将其收集到UITextView inputView。当我需要acess pickerView时,我得到这样的结果。
UIPickerView *picker = (UIPickerView *)self.myTextField.inputView;
#6
1
You have to ensure that the view you will assign to
inputView
orinputAccessoryView
don't belong to any parent view.您必须确保将分配给inputView或inputAccessoryView的视图不属于任何父视图。
This error is especially annoying as any "input view" created in a storyboard (and thus added to the VC's view
) cannot be set as the inputView
or inputAccessoryView
without causing this crash.
这个错误尤其令人反感,因为在故事板中创建的任何“输入视图”(因此添加到VC视图中)不能被设置为inputView或inputAccessoryView,而不会导致此崩溃。
If the input view is not added to the VC's view
, the input view will not be available for visual editing in the Interface Builder Storyboard. It's only visible in the Storyboard's left pane.
如果没有将输入视图添加到VC视图中,那么在Interface Builder故事板中,输入视图将无法用于可视化编辑。它只在故事板的左窗格中可见。
How to connect Xcode Storyboard's "Simulated Metrics" toolbar to an actual IBOutlet UIToolbar?
如何将Xcode Storyboard的“模拟度量”工具栏连接到实际的IBOutlet UIToolbar?
I'd prefer to make an IB Connection to the inputAccessoryView
directly in the Storyboard. That causes this crash. A solution I found is to make a secondary IBOutlet connected to the view in the Storyboard, then in viewDidLoad
remove it from the super view then immediately assign to inputAccessoryView
. Not sure if I'll end up using this.
我希望在故事板中直接连接到inputAccessoryView。导致这种崩溃。我找到的一个解决方案是将第二个IBOutlet连接到故事板中的视图,然后在viewDidLoad中从父视图中删除它,然后立即赋给inputAccessoryView。不知道我最后会不会用这个。
- (void) viewDidLoad {
// ...
[self.keybordView removeFromSuperview];
self.inputAccessoryView = self.keybordView;
}
#7
0
I had the same problem when I tried to setup my UIDatePicker in my UITextField
当我试图在UITextField设置我的UIDatePicker时,我遇到了同样的问题。
- (void)setupViews {
...
dobField.inputView = aDatePicker; // Here was the problem
...
}
My solution, I just "alloc" and "init" my datePicker in ViewDidLoad
我的解决方案,我只是“alloc”和“init”我的datePicker在ViewDidLoad。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
...
aDatePicker = [[UIDatePicker alloc] init]; // My solution
...
}
#8
0
Calling removeFromSuperView
in viewDidLoad
doesn't seem to work properly in modals. I ended up setting the view hidden, and then removing it from superView in viewDidAppear
.
在viewDidLoad中调用removeFromSuperView似乎不适合在modals中工作。我最后设置了隐藏的视图,然后在viewDidAppear中从superView中删除它。
#9
0
Most answers I was were related to code changes. I found out that deleting an outlet to the UIView inside the main view fixed it. https://*.com/a/40037236/464313
我的大多数答案都与代码变更有关。我发现在主视图中删除一个outlet到UIView的主要视图是固定的。https://*.com/a/40037236/464313
#10
0
My solution for this problem was to add view to inputView, but not to add view controller to parent.
我解决这个问题的方法是将视图添加到inputView中,而不是将视图控制器添加到父视图。
#11
0
I had the same error when I return any view from storyboard as inputAccessoryView
. I fixed it with childViewController. See my answer here.
当我返回任何从storyboard作为inputAccessoryView的视图时,我有同样的错误。我用childViewController修复它。看到我的答案。
#12
0
My problem was that I have named a view having a textField 'inputAccessoryView'...
我的问题是,我已经给一个视图命名为textField 'inputAccessoryView'…
@property (weak, nonatomic) IBOutlet CustomView *inputAccessoryView;
Error:
错误:
Terminating app due to uncaught exception
'UIViewControllerHierarchyInconsistency', reason: 'child view
controller:<UICompatibilityInputViewController: 0x7fed7063a1a0> should
have parent view controller:<MyViewController: 0x7fed70606f00> but
requested parent is:<UIInputWindowController: 0x7fed710cde00>'
Solution:
解决方案:
Check the naming; do not override if not needed.
检查命名;如果不需要,不要重写。
#1
100
I encountered this problem before.
我以前遇到过这个问题。
Problem:
问题:
- You have to ensure that the view you will assign to
inputView
orinputAccessoryView
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. - 您必须确保将分配给inputView或inputAccessoryView的视图不属于任何父视图。当您在一个视图控制器中从一个xib创建这些视图时,默认情况下它们被设置为一个超视图的子视图。
Solution Tips:
解决方案建议:
- Use the method
removeFromSuperview
on the view you will assign toinputView
orinputAccessoryView
- 在您将分配给inputView或inputAccessoryView的视图上使用removeFromSuperview方法。
#2
17
Just before becomeFirstResponder
remove the View you use for input from the superview :
在成为firstresponder之前,要删除从超级视图中输入的视图:
mTextField.inputView = mInputVeiw;
[mInputVeiw removeFromSuperview];
[mTextField becomeFirstResponder];
Hope it helps.
希望它可以帮助。
#3
2
I figured it out. I'm not sure what the issue was before but instead of linking a UIView
in interface builder, I instead created a UIView
programmatically and it worked fine.
我想出来。我不知道之前的问题是什么,但是我没有在接口构建器中链接一个UIView,而是通过编程的方式创建了一个UIView,而且效果很好。
#4
1
Yeah, the Tuyen Nguyen solution did not work for me. What worked for me in iOS8 / XCode 6 for setting an inputAccessoryView was not to removeFromSuperview BUT to
是啊,阮先生的办法对我不起作用。我在iOS8 / XCode 6中为我设置了一个inputAccessoryView,而不是从superview中删除,而是!
[[UIApplication sharedApplication].keyWindow addSubview:**MyViewToBeTheUIAccessoryView**];
I hope this helps someone.
我希望这能帮助别人。
#5
1
I found the solution creating the UIView programmatically (Like suggested by Milo), but it crashes when its used like a @property. In my case, I needed to create the UIPickerView instance in viewDidLoad and assing to UITextView inputView. When I need to acess the pickerView I get it like this
我找到了以编程方式创建UIView的解决方案(就像Milo所建议的那样),但是当它使用的是@property时就崩溃了。在我的例子中,我需要在viewDidLoad中创建UIPickerView实例,并将其收集到UITextView inputView。当我需要acess pickerView时,我得到这样的结果。
UIPickerView *picker = (UIPickerView *)self.myTextField.inputView;
#6
1
You have to ensure that the view you will assign to
inputView
orinputAccessoryView
don't belong to any parent view.您必须确保将分配给inputView或inputAccessoryView的视图不属于任何父视图。
This error is especially annoying as any "input view" created in a storyboard (and thus added to the VC's view
) cannot be set as the inputView
or inputAccessoryView
without causing this crash.
这个错误尤其令人反感,因为在故事板中创建的任何“输入视图”(因此添加到VC视图中)不能被设置为inputView或inputAccessoryView,而不会导致此崩溃。
If the input view is not added to the VC's view
, the input view will not be available for visual editing in the Interface Builder Storyboard. It's only visible in the Storyboard's left pane.
如果没有将输入视图添加到VC视图中,那么在Interface Builder故事板中,输入视图将无法用于可视化编辑。它只在故事板的左窗格中可见。
How to connect Xcode Storyboard's "Simulated Metrics" toolbar to an actual IBOutlet UIToolbar?
如何将Xcode Storyboard的“模拟度量”工具栏连接到实际的IBOutlet UIToolbar?
I'd prefer to make an IB Connection to the inputAccessoryView
directly in the Storyboard. That causes this crash. A solution I found is to make a secondary IBOutlet connected to the view in the Storyboard, then in viewDidLoad
remove it from the super view then immediately assign to inputAccessoryView
. Not sure if I'll end up using this.
我希望在故事板中直接连接到inputAccessoryView。导致这种崩溃。我找到的一个解决方案是将第二个IBOutlet连接到故事板中的视图,然后在viewDidLoad中从父视图中删除它,然后立即赋给inputAccessoryView。不知道我最后会不会用这个。
- (void) viewDidLoad {
// ...
[self.keybordView removeFromSuperview];
self.inputAccessoryView = self.keybordView;
}
#7
0
I had the same problem when I tried to setup my UIDatePicker in my UITextField
当我试图在UITextField设置我的UIDatePicker时,我遇到了同样的问题。
- (void)setupViews {
...
dobField.inputView = aDatePicker; // Here was the problem
...
}
My solution, I just "alloc" and "init" my datePicker in ViewDidLoad
我的解决方案,我只是“alloc”和“init”我的datePicker在ViewDidLoad。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
...
aDatePicker = [[UIDatePicker alloc] init]; // My solution
...
}
#8
0
Calling removeFromSuperView
in viewDidLoad
doesn't seem to work properly in modals. I ended up setting the view hidden, and then removing it from superView in viewDidAppear
.
在viewDidLoad中调用removeFromSuperView似乎不适合在modals中工作。我最后设置了隐藏的视图,然后在viewDidAppear中从superView中删除它。
#9
0
Most answers I was were related to code changes. I found out that deleting an outlet to the UIView inside the main view fixed it. https://*.com/a/40037236/464313
我的大多数答案都与代码变更有关。我发现在主视图中删除一个outlet到UIView的主要视图是固定的。https://*.com/a/40037236/464313
#10
0
My solution for this problem was to add view to inputView, but not to add view controller to parent.
我解决这个问题的方法是将视图添加到inputView中,而不是将视图控制器添加到父视图。
#11
0
I had the same error when I return any view from storyboard as inputAccessoryView
. I fixed it with childViewController. See my answer here.
当我返回任何从storyboard作为inputAccessoryView的视图时,我有同样的错误。我用childViewController修复它。看到我的答案。
#12
0
My problem was that I have named a view having a textField 'inputAccessoryView'...
我的问题是,我已经给一个视图命名为textField 'inputAccessoryView'…
@property (weak, nonatomic) IBOutlet CustomView *inputAccessoryView;
Error:
错误:
Terminating app due to uncaught exception
'UIViewControllerHierarchyInconsistency', reason: 'child view
controller:<UICompatibilityInputViewController: 0x7fed7063a1a0> should
have parent view controller:<MyViewController: 0x7fed70606f00> but
requested parent is:<UIInputWindowController: 0x7fed710cde00>'
Solution:
解决方案:
Check the naming; do not override if not needed.
检查命名;如果不需要,不要重写。