Application termination due to the uncaught exception "UIViewControllerHierarchyInconsistency",

I created a toolbar on a two-button collector and worked on ios7 when I ran an ios8 crash:

Completion of the second application to the excluded exception "UIViewControllerHierarchyInconsistency", reason: "child view" controller: must Have a parent view controller: but requested parent: '

This is a 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; 

You know that I realized that inputAccessoryView going to destroy the application, I also asked Apple engineers, and they told me that this is a beta test problem, but now with GM it continues to give the same problem.

What should I do?

+13
ios inputaccessoryview uipickerview
Sep 10 '14 at 9:33
source share
5 answers

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

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

Before (an error occurs)

 UITextField* someTF; View* customView; UIViewController *mainVC; [mainVC.view addSubview:customView]; someTF.inputView = customView; 

After (works well)

 UITextField* someTF; View* customView; UIViewController *mainVC; // [mainVC.view addSubview:customView]; <-- delete this line someTF.inputView = customView; 
+12
Sep 14 '14 at 8:12
source share

For ios 8 If you added UIPickerView on self.view:

 [self.view addSubview:piker]; 

Remove this line from your code and then install:

 textField.inputView = piker; 

thank

+5
Sep 23 '14 at 9:23
source share

UIDatePickerView should not be a child of a superview

Problem

You must make sure that the view you assign to inputView or inputAccessoryView does not belong to any parent view. Maybe when you create these views from xib inside the ViewController, by default they are areas of the add-in.

Tips for solving :

Using the removeFromSuperview method to view, you assign an inputView or inputAccessoryView

see details in this link

Error adding input type to iOS 8 text box

+3
Feb 18 '15 at 7:12
source share

I had the same problem when I was trying to configure my UIDatePicker in a UITextField

 - (void)setupViews { ... dobField.inputView = aDatePicker; // Here was the problem ... } 

My solution, I just “assign” and “run” my datePicker in ViewDidLoad

 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ... aDatePicker = [[UIDatePicker alloc] init]; // My solution // If you need UIDatePickerModeDate aDatePicker.datePickerMode = UIDatePickerModeDate; ... } 
0
Sep 30 '14 at 15:12
source share

I ran into this problem. My code had no addSubView, but my xib has a UIView with a different UIView inside. The UIView inside had an exit to the UIView property like this:

 @property(nonatomic, strong) IBOutlet UIView *inputView; 

It was decided to open xib, right-click the File icon (yellow cube icon), which will open a list of views and points and delete the link by unchecking the box on the right.

0
Oct. 14 '16 at 7:20
source share



All Articles