Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',

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

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

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;

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.

What do I do?

like image 396
Marco Giraudo Avatar asked Sep 10 '14 09:09

Marco Giraudo


3 Answers

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

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.)

Before (occurs error)

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

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

After (working well)

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

//  [mainVC.view addSubview:customView];  <-- delete this line
someTF.inputView = customView;
like image 61
Dale Avatar answered Nov 19 '22 11:11

Dale


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

[self.view addSubview:piker];

Please remove this line from your Code, then set:

textField.inputView = piker;

Thanks

like image 42
Jugal K Balara Avatar answered Nov 19 '22 09:11

Jugal K Balara


UIDatePickerView should not be child class of any super view

Problem:

You have to ensure that the view you will assign to inputView or inputAccessoryView don't belong to any parent view. Maybe when you create these views from xib inside a ViewController, by default they are subviews of a superview.

Solution Tips:

Using method removeFromSuperview for view you will assign to inputView or inputAccessoryView

like image 2
umairhhhs Avatar answered Nov 19 '22 10:11

umairhhhs