Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',
Asked Answered
C

5

15

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?

Chalfant answered 10/9, 2014 at 9:33 Comment(2)
show the exception log..Kulda
I am running into this problem too with the inputAccessoryView. In our case we are trying to set the inputaccessoryView to a "parent" view that is defined in the XIB that specifies a UITExtView and a button. When the user clicks in the UITExtView the keyboard is supposed to slide up and the UITExtView and button slide up (as part of the accessory view). Worked fine in IOS7. No idea of the fix yet...Tait
C
15

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;
Canto answered 14/9, 2014 at 8:12 Comment(0)
H
6

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

Heffner answered 23/9, 2014 at 9:23 Comment(1)
I was facing with problem like below (it was because of UIPicker like you mentioned in your answer) and your answer solved my issue. Thank you. --------------------------------- 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x7bf4cb40> should have parent view controller:<UICompatibilityInputViewController: 0x7c9960f0> but requested parent is:<UIInputWindowController: 0x7e3e1c00>' terminating with uncaught exception of type NSException abort() calledPiled
B
2

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

Bartolommeo answered 18/2, 2015 at 7:12 Comment(0)
E
0

I had the same problem when I tried to setup my UIDatePicker in my UITextField

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

My solution, I just "alloc" and "init" 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;
    ...
}
Edition answered 30/9, 2014 at 15:12 Comment(0)
D
0

I ran into this issue also. My code didn't have any addSubView but my xib has a UIView with another UIView inside. The UIView inside had an outlet to a UIView property as so:

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

What solved it was to open the xib, right click the "File's Owner" (yellow cube icon) which opens the list of views and outlets and deleting the link by unchecking the circle to the right.

Determinative answered 14/10, 2016 at 7:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.