ios – 由于未捕获的异常UIViewControllerHierarchyInconsistency终止应用程序,

我在两个按钮上创建了一个工具栏,并在ios7上运行,当我在ios8崩溃时运行:

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

这是在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,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继续给同样的问题.

我该怎么办?

解决方法

我在iOS 8上也有同样的例外,现在修正为以下代码.

关键是,您不应该添加输入视图作为视图控制器视图的子视图.
(我不知道为什么iOS 7中的代码运行良好,在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;

相关文章

背景 前端时间产品经理决定使用百度统计,使得 工程B 中原统计sdk-友盟统计,需要被去除。之前尝试去除...
结论: alloc负责分配内存和创建对象对应的isa指针; init只是返回alloc生成的对象。 所以alloc后,多次...
更新 如果UI愿意把启动图切割成n份,按一定约束在launchscreen.storyboard中进行排版,启动图效果会更好...
最近在看一本书《Effective OC 2.0》,今天看到有个tip是OC适中循环各自优劣性,作者最终推荐此块循环。...
// // ViewController.m // paintCodeTestOC //gif // Created by LongMa on 2019/7/25. // #import &a...
背景介绍 一般情况下,出于省电、权限、合理性等因素考虑,给人的感觉是很多奇怪的需求安卓可以实现,但...