NSInteralInconsistencyException - UIKeyboardLayoutAlignmentView

前端 未结 4 2117
旧时难觅i
旧时难觅i 2020-12-06 04:42

I am getting the follow crash in my reports but I don\'t have a clue as to where to start looking! - any help appreciated. I have no calls or reference to UIKeyboardLayoutA

相关标签:
4条回答
  • 2020-12-06 04:52

    Ok, problem found an fixed. On iOS8.3 if you the keyboard is being displayed and then you try to display a UIAlertView or UIAlertController that has an input field you will get this crash.

    Simple solution (for me) was to insert

    [self.window endEditing:YES]; 
    

    or

    [self.view endEditing:YES];
    

    in front of any alerts that do this and it no longer crashes

    Update

    In some cases I have also needed the following line (as outlined by Oren below), with the endEditing AND this line I have zero issues - but with one OR the other I have seen the odd crash which is weird - but the combo attack seems to work !

    UITextField *txtEmail = [alertView textFieldAtIndex:0];
    [txtEmail becomeFirstResponder];
    
    0 讨论(0)
  • 2020-12-06 04:53

    This might help someone with the same issue. I came here to check out your answer, but it didn't work for me.

    iOS 8.3 UIAlertController crashes when trying to add a textfield

    To reiterate what's on the other thread, I solved it by setting the animated flag to "NO" when presenting the UIAlertController

    [self presentViewController:alert animated:NO completion:nil];
    
    0 讨论(0)
  • 2020-12-06 04:53

    I had the same issue using the Cordova Dialogs plugin in an Ionic app. It seems as of iOS 8.3 whenever a notification or alert is called and the keyboard is already visible, it tries to open another keyboard which causes the crash. I added this one line to the CDVNotification.m file in the plugin.

     if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) {
        alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
        UITextField* textField = [alertView textFieldAtIndex:0];
        **[textField becomeFirstResponder];** //added this line to Fix :)
        textField.text = defaultText;
    }
    
    0 讨论(0)
  • 2020-12-06 04:59

    This is definitely a bug with iOS8.3 when showing a UIAlertView or UIAlertController when the keyboard is already shown.

    A workaround is to assign the alert view's textfield as the first responder. This works better than hiding the keyboard via resignFirstResponder or endEditing because the keyboard won't flicker.

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle.......
    alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
    
    UITextField *txtEmail = [alertView textFieldAtIndex:0];
    [txtEmail becomeFirstResponder];
    
    [alertView show];
    
    0 讨论(0)
提交回复
热议问题