由于未捕获的异常'UIViewControllerHierarchyInconsistency'而终止应用, [英] Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',

查看:460
本文介绍了由于未捕获的异常'UIViewControllerHierarchyInconsistency'而终止应用,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在选择器上方创建了一个带有两个按钮的工具栏并在ios7上工作,当我在ios8崩溃时运行:

I created a toolbar above the picker with two buttons and worked on ios7, when i run in ios8 crash:


终止应用程序二到未捕获的异常
'UIViewControllerHierarchyInconsistency',原因:'子视图
控制器:应该是
有父视图控制器:但是请求的父级是:'

Terminating app two to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller: Should Have parent view controller: but requested parent is: '

这是在ios7中安静运行的一段代码:

This is the piece of code that worked quietly in ios7:

 expiredPromoTextField.inputView = DatePicker;
 expiredPromoTextField.delegate = self;
 quantityPromoTextField.inputView = quantityPicker;
 quantityPromoTextField.delegate = self;


 // Create button to close the UIPickerView
 UIToolbar * mypickerToolbar = [[UIToolbar alloc] initWithFrame: CGRectMake (0, 0, 320, 56)];
 mypickerToolbar.barStyle = UIBarStyleBlackTranslucent;
 [mypickerToolbar sizeToFit];
 NSMutableArray * barItems = [[NSMutableArray alloc] init];
 UIBarButtonItem * CancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCancel target: self action:selector (cancelDoneClicked)];
 [barItems addObject: CancelBtn];
 UIBarButtonItem * FLEXspace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: self action: nil];
 [barItems addObject: FLEXspace];
 UIBarButtonItem * doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target: self action:selector (pickerDoneClicked :)];
 [barItems addObject: doneBtn];
 [mypickerToolbar setItems: barItems animated: YES];
 [quantityPicker setShowsSelectionIndicator: YES];

 expiredPromoTextField.inputAccessoryView = mypickerToolbar;
 quantityPromoTextField.inputAccessoryView = mypickerToolbar;

你知道我意识到的是 inputAccessoryView 将要崩溃的应用程序,我也问苹果公司的工程师,他们告诉我这是测试版的问题,但现在GM继续给出同样的问题。

You know what I realized is that inputAccessoryView is going to crash the app, I also asked engineers of Apple and they told me that it was a problem with the beta, but now with the GM continues to give the same problem.

我该怎么办?

推荐答案

我在iOS 8上遇到了同样的例外情况,现在修复为以下代码。

I had the same exception on iOS 8 and now fixed as the following codes.

重点是,您不应将输入视图添加为视图控制器视图的子视图。
(我不知道为什么代码在iOS 7中运行良好,在iOS 8中不再运行良好。)

The point is, you should not add an input view as a child view of view controller's view. (I have no idea why the code worked well in iOS 7 is no longer working well in iOS 8.)

之前(发生错误)

UITextField* someTF;
View* customView;
UIViewController *mainVC;

[mainVC.view addSubview:customView];
someTF.inputView = customView;

之后(运作良好)

UITextField* someTF;
View* customView;
UIViewController *mainVC;

//  [mainVC.view addSubview:customView];  <-- delete this line
someTF.inputView = customView;

这篇关于由于未捕获的异常'UIViewControllerHierarchyInconsistency'而终止应用,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆