Nsinteralinconsistencyexception - Uikeyboardlayoutalignmentview

NSInteralInconsistencyException - UIKeyboardLayoutAlignmentView

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];

Keypads showing on different views, causes UIKeyboardLayoutAlignmentView constraint error

OK, after researching the issue I discovered that I needed to observe the application state. On notification then check if various objects are load and if so, resignFirstResponder when the keyboard is shown (aka is editing) (I had a text field in an UIAlertView), dismiss an UIAlertView and then dismiss in the view controller used in dialog.

Shesh... so not as simple as I was hoping.
Although this is an edge case for me, I figured I should fix it.

I also found this which will dissmiss alertviews https://github.com/sdarlington/WSLViewAutoDismiss

Which will save me a lot of hassle in simpler scenarios.

Apparently since iOS4, Apple recommends cancelling UIAlertViews and UIActionSheets when an application becomes active.

NSInternalInconsistencyException? The layout constraints still need update after sending

After a simple Google search I found the answer to your problem.

On iOS 8.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.

iOS 8.3 UIAlertController crashes when trying to add a textfield

Edit: This fix changes depending on if you are building with Xcode 6 or Xcode 7, so I've added the relevant information for both versions of Xcode.


I ran into this today and what it's saying is that it can't add the text field to the view controller's view or that it can't add auto-layout constraints to its superview. This seems to be because it hasn't created the superview to add it to yet, and so it all panics and crashes.

Simple fix I found is add the text field after you tell the alert controller to present. That fixed it to me, though I'm not sure if it'll affect anything like the text field popping in as the alert is presenting.

Built with Xcode 6

let alertController = UIAlertController(title: "Enter Name", message:nil, preferredStyle: .Alert)

let okAction = UIAlertAction(title: "Ok", style: .Default) { (_) -> Void in
// Some action here
}
alertController.addAction(okAction)

presentViewController(alertController, animated: true, completion: nil)

// Add any text fields after presenting the alert controller to fix crash in iOS 8.3
alertController.addTextFieldWithConfigurationHandler { (textfield) -> Void in
textfield.placeholder = "Name"
}

P.s. As a side note from your code example, remember with Swift, you don't need to use ; at the end of every line, though it doesn't matter if you do. /p>


Built with Xcode 7

When you build your app using Xcode 7, it seems like Apple have fixed the issue. Using the method shown above will no longer show a text field in iOS 9 (even though it still shows correctly in iOS 8).

Below is a snippet of code, how it should have been the whole time, and when built in Xcode 7 it runs correctly in iOS 8 and iOS 9.

let alertController = UIAlertController(title: "Enter Name", message:nil, preferredStyle: .Alert)

alertController.addTextFieldWithConfigurationHandler { (textfield) -> Void in
textfield.placeholder = "Name"
}

let okAction = UIAlertAction(title: "Ok", style: .Default) { (_) -> Void in
// Some action here
}
alertController.addAction(okAction)

presentViewController(alertController, animated: true, completion: nil)

Tested in Swift 2.0 and Obj-C with Xcode 7 GM (7A218)

I get some layout constraints error in iOS

If you implemented updateConstraints you need to call [super updateConstraints]; within your implementation.

See https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/index.html#//apple_ref/occ/instm/UIView/updateConstraints

UPDATE:

_UIKeyboardLayoutAlignmentView is an Apple internal keyboard view. Most likely something is crashing while it is presented.

See this Radar (Apple bug report) and these answers for a potential solution.
The bug seems to be iOS 8.3 specific.

https://openradar.appspot.com/20615507

NSInteralInconsistencyException - UIKeyboardLayoutAlignmentView

iOS 8.3 UIAlertController crashes when trying to add a textfield

How do I edit CSS in Chrome like in Firebug for Firefox?

Try StyleBot. It can also save edited CSS.



Related Topics



Leave a reply



Submit