Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',

后端 未结 5 1891
借酒劲吻你
借酒劲吻你 2020-12-16 14:59

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 \'UIVi

相关标签:
5条回答
  • 2020-12-16 15:39

    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;
        ...
    }
    
    0 讨论(0)
  • 2020-12-16 15:41

    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

    0 讨论(0)
  • 2020-12-16 15:43

    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

    0 讨论(0)
  • 2020-12-16 15:45

    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;
    
    0 讨论(0)
  • 2020-12-16 15:45

    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.

    0 讨论(0)
提交回复
热议问题