2014-09-16 3 views
5

J'ai une application qui fonctionne bien dans iOS 7 et Xcode 5. Dès que je l'ai mis à jour vers iOS 8 et Xcode 6, il se bloque lorsque l'application essaie de faire glisser UIDatePicker dans le voir quand un objet textField est tapé. J'utilise le storyboard. Quelqu'un a une idée pourquoi?UIViewControllerHierarchyInconsistency bloque l'application uniquement dans iOS 8 et Xcode 6

J'ai lu à ce sujet mais c'est pour Xib.

App crashes on IOS 6 - UIViewControllerHierarchyInconsistency

s'il vous plaît aider grâce

mon code:

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 

    //set picker color start 
    [self.myDatePicker setBackgroundColor:[UIColor greenColor]]; 


    //set picker color finish 
    //calculate bounds start 
    CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField]; 
    CGRect viewRect = [self.view.window convertRect:self.view.bounds fromView:self.view]; 
    //calculate bounds finish 
    //calculate the fraction between the top and bottom of the middle section for the text field's midline start 
    CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height; 
    CGFloat numerator = midline - viewRect.origin.y 
    - MINIMUM_SCROLL_FRACTION * viewRect.size.height; 
    CGFloat denominator = (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION) 
    * viewRect.size.height; 
    CGFloat heightFraction = numerator/denominator; 
    //calculate the fraction between the top and bottom of the middle section for the text field's midline finish 
    //Clamp this fraction so that the top section is all "0.0" and the bottom section is all "1.0 start 
    if (heightFraction < 0.0) 
    { 
     heightFraction = 0.0; 
    } 
    else if (heightFraction > 1.0) 
    { 
     heightFraction = 1.0; 
    } 
    //Clamp this fraction so that the top section is all "0.0" and the bottom section is all "1.0 finish 
    /*start 
    Now take this fraction and convert it into an amount to scroll by multiplying by the keyboard height for the current screen orientation. Notice the calls to floor so that we only scroll by whole pixel amounts */ 
    UIInterfaceOrientation orientation = 
    [[UIApplication sharedApplication] statusBarOrientation]; 
    if (orientation == UIInterfaceOrientationPortrait || 
    orientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
    animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction); 
    } 
    else 
    { 
    animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction); 
    } 
    //finish 
    //Finally, apply the animation start 
    CGRect viewFrame = self.view.frame; 
    viewFrame.origin.y -= animatedDistance; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION]; 
    [self.view addSubview:self.myDatePicker]; 
    [self.view setFrame:viewFrame]; 

    [UIView commitAnimations]; 


} 
    //Finally, apply the animation finish 
    //Animate back again start 

mon journal crash

2014-09-14 13:12:52.930 Pay 2014-15 free[2191:83060] 
*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', 
reason: 'child view controller:<UICompatibilityInputViewController: 0x7be0a570> should have parent view controller:<AddHoursViewController: 0x7c38e800> but requested parent is:<UIInputWindowController: 0x7c238a00>' 
*** First throw call stack: 
(
    0 CoreFoundation      0x02101df6 __exceptionPreprocess + 182 
    1 libobjc.A.dylib      0x01d8ba97 objc_exception_throw + 44 
    2 CoreFoundation      0x02101d1d +[NSException raise:format:] + 141 
    3 UIKit        0x008cff9c -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 210 
    4 UIKit        0x00f4b44d -[UIInputWindowController changeToInputViewSet:] + 576 
    5 UIKit        0x00f4c1be __43-[UIInputWindowController setInputViewSet:]_block_invoke + 103 
    6 UIKit        0x007f73bf +[UIView(Animation) performWithoutAnimation:] + 82 
    7 UIKit        0x00f4bf9c -[UIInputWindowController setInputViewSet:] + 374 
    8 UIKit        0x00ce9101 __64-[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:]_block_invoke1459 + 43 
    9 UIKit        0x00f473af -[UIInputWindowController performOperations:withAnimationStyle:] + 56 
    10 UIKit        0x00ce9006 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1242 
    11 UIKit        0x00ce91df -[UIPeripheralHost(UIKitInternal) setInputViews:animated:] + 73 
    12 UIKit        0x00ce922b -[UIPeripheralHost(UIKitInternal) setInputViews:] + 68 
    13 UIKit        0x00ce1478 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 1803 
    14 UIKit        0x0092be95 -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 316 
    15 UIKit        0x0092b1dc -[UIResponder becomeFirstResponder] + 562 
    16 UIKit        0x007f1de0 -[UIView(Hierarchy) becomeFirstResponder] + 114 
    17 UIKit        0x00fb7ffb -[UITextField becomeFirstResponder] + 51 
    18 UIKit        0x00bbde8f -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 200 
    19 UIKit        0x00bc04b6 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2762 
    20 UIKit        0x00bb3d27 _UIGestureRecognizerSendActions + 327 
    21 UIKit        0x00bb25a4 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 561 
    22 UIKit        0x00bb45ed -[UIGestureRecognizer _delayedUpdateGesture] + 60 
    23 UIKit        0x00bb7f6a ___UIGestureRecognizerUpdate_block_invoke661 + 57 
    24 UIKit        0x00bb7e2d _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317 
    25 UIKit        0x00babd36 _UIGestureRecognizerUpdate + 3720 
    26 UIKit        0x007c771b -[UIWindow _sendGesturesForEvent:] + 1356 
    27 UIKit        0x007c857f -[UIWindow sendEvent:] + 769 
    28 UIKit        0x0078daa9 -[UIApplication sendEvent:] + 242 
    29 UIKit        0x0079d8de _UIApplicationHandleEventFromQueueEvent + 20690 
    30 UIKit        0x00772079 _UIApplicationHandleEventQueue + 2206 
    31 CoreFoundation      0x020257bf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 
    32 CoreFoundation      0x0201b2cd __CFRunLoopDoSources0 + 253 
    33 CoreFoundation      0x0201a828 __CFRunLoopRun + 952 
    34 CoreFoundation      0x0201a1ab CFRunLoopRunSpecific + 443 
    35 CoreFoundation      0x02019fdb CFRunLoopRunInMode + 123 
    36 GraphicsServices     0x0394624f GSEventRunModal + 192 
    37 GraphicsServices     0x0394608c GSEventRun + 104 
    38 UIKit        0x00775e16 UIApplicationMain + 1526 
    39 Pay 2014-15 free     0x0014ed7d main + 141 
    40 libdyld.dylib      0x0736cac9 start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) `enter code here` 
+1

Pouvez-vous montrer le code que vous utilisez? –

+0

code ajouté en éditant la question. Regardez ceci, s'il vous plaît. UIDatePicker est ajouté au storyboard et connecté à une propriété @Property (nonatomic, strong) IBOutlet * mypickerVirw; Si je supprime le système de connexion Clavier monter, pas de crash.J'ai essayé [textField resignFirstResponder]; Il arrête le clavier mais UIDatePickerView ne s'affiche pas et l'application se bloque. – user2511630

+0

Même ici! des nouvelles? –

Répondre

0
-(void)viewDidLoad 
       { 
      //init and allocate(my problem was addind nil object into view.   
     self.myDatePicker = [[UIDatePicker alloc]init]; 

        [self.myDatePicker setDatePickerMode:UIDatePickerModeCountDownTimer]; 

     //to get text off picker 
        [self.myDatePicker addTarget:self action:@selector(textFieldDidEndEditing:) forControlEvents:UIControlEventValueChanged]; 

     //to hide picker 
        _tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)]; 
       } 


    -(BOOL)textFieldShouldEndEditing:(UITextField *)textField 
       { 
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init]; 
        [dateFormat setDateFormat:@"HH:mm"]; 
        NSDate *date = self.myDatePicker.date; 
        //or select pickerViewMode 

        switch (textField.tag) 
       { 
        case 1: //pulls selected text into textField 
         self.textField1.text = [dateFormat stringFromDate:date]; 
         break; 
       } 
       } 

    -(void)hideKeyboard 
       { 
       //NSLog(@"6 hideKeyboard"); 
       [self.textField1 resignFirstResponder]; 
       } 
+9

Devrait expliquer le code, pas seulement le fournir – mattblessed

+0

Le code dit "mon problème était l'objet Addind nil dans la vue", donc je suppose que c'est l'explication. Ne m'aide pas, mais au moins c'est la solution à son problème. Poursuivant mes études ... – JOM

0

Le pro de base blem a probablement été provoqué en ajoutant le sélecteur de date en tant que vue enfant de la vue des contrôleurs de vue.

Retrait de la ligne suivante aurait empêché ceci:

[self.view addSubview:self.myDatePicker]; 

voir https://stackoverflow.com/a/25831317/1871400

1
sélecteur de date

ne devrait pas être l'enfant d'une superbe vue

Problème:

Vous devez vous assurer que la vue que vous assignera à inputView ou inputAccessoryView n'appartiennent à aucune vue parent. Peut-être que lorsque vous créez ces vues depuis xib à l'intérieur d'un ViewController, elles sont par défaut des sous-vues d'une vue d'ensemble.

Conseils Solution:

en utilisant la méthode removeFromSuperview pour la vue que vous assignera à inputView ou inputAccessoryView

voir détail dans ce lien

Error when adding input view to textfield iOS 8

3

Soit vous créez sélecteur de date programatically ou si vous l'utilisez en tant que composant déposé, effectuez les étapes ci-dessous

1.Créez Programatically

datePicker = [[UIDatePicker alloc]init]; 
[datePicker setDate:[NSDate date]]; 
//NSString *maxDateString = @"01-Jan-2012"; 
NSString *theMinimumDate = @"01-Jan-1976"; 
// the date formatter used to convert string to date 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
// the specific format to use 
dateFormatter.dateFormat = @"dd-MMM-yyyy"; 
// converting string to date 
NSDate *theMaximumDate = [NSDate date];//[dateFormatter dateFromString: maxDateString]; 
NSDate *theminimumDate = [dateFormatter dateFromString: theMinimumDate]; 

// repeat the same logic for theMinimumDate if needed 
// here you can assign the max and min dates to your datePicker 
[datePicker setMaximumDate:theMaximumDate];//the max age restriction (if needed, or else dont use this line) 
[datePicker setMinimumDate:theminimumDate]; //the min age restriction 

// set the mode 
[datePicker setDatePickerMode:UIDatePickerModeDate]; 
// Do any additional setup after loading the view from its nib. 
[datePicker addTarget:self action:@selector(updateTextField:) forControlEvents:UIControlEventValueChanged]; 

// and finally set the datePicker as the input mode of your textfield 
[Textfield setInputView:datePicker]; 

2.From Xib

[self.DatePickerView removeFromSuperview]; 
[Textfield setInputView:self.DatePickerView]; 
[Textfield setInputView:self.DatePickerView]; 
Questions connexes