Nslayoutconstraint Crashes Viewcontroller

NSLayoutConstraint crashes ViewController]

You must uncheck the box in your NIB that says "use auto layout" before you try to run this thing on a device that doesn't support the new NSLayoutConstraint class.

Sample Image

App is crashing on NSLayoutConstraint when added programmatically

Height and width constraints belong to the view they pertain to. Centering and positioning belong to that view's parent so you must add these two to the parent, not the view itself.

Adding constraints crashes app

You are adding constraint for a view that is not in your view hierarchy, so you first need add your desired view as subview and after that you can setup your constraints without a crash in the process

You need move this line

self.view.addSubview(bottomSheet!)

above this one

bottomSheet?.setUp(parentController: self)

presentViewController: crash on iOS 6 (AutoLayout)

I believe this is an issue with Xcode's new interface builder. Did you happen to build your .xib using Xcode 4.5's interface builder? I've run into this same problem just now, and I think that's the problem. My app runs on iOS 6, but not anything older.

And you need to make sure you turn off Use Auto Layout for your xibs.

That can be done by:

  1. Open your xib.
  2. Go to the File Inspector tab.
  3. Find the Interface Builder Document section on the right toolbar.
  4. Uncheck the Use Auto Layout option.

Adding leading constraint programmatically crashes app

First of all,

view.addSubview(someView)
someView.translatesAutoresizingMaskIntoConstraints = false

should come before the constraints phase; you have to apply the constraints AFTER someView is added to its superview.

Also, if you are targeting iOS 9, I'd advise you to use layout anchors like

let widthConstraint = someView.widthAnchor.constraint(equalToConstant: 50.0)
let heightConstraint = someView.heightAnchor.constraint(equalToConstant: 50.0)
let leadingConstraint = someView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20.0)
NSLayoutConstraint.activate([widthConstraint, heightConstraint, leadingConstraint])

This way you don't have to worry about which view to apply the constraints to.

Finally (and to clear up your doubt), if you can't use layout anchors, you should add the leading constraint to the superview, not the view.

Tracking NSLayoutConstraint Crash?

Hey I don't think that _NSLayoutConstraintNumberExceedsLimit() is causing the crash. It is just a warning. But still, it should be fixed ideally.

Focusing on the crash for now.
The problem lies with :

[NSLayoutConstraint
constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]:
A constraint cannot be made between a leading/trailing attribute and a
right/left attribute. Use leading/trailing for both or neither.'

Maybe somewhere in your constraints you have associated NSLayoutAttributeLeading for an item to NSLayoutAttributeLeft.
Can you put the code where you add the constraints?

How to debug inconsistent crash to SIGABRT and NSLayoutConstraint constant is not finite! That's illegal. constant:nan

After a bit more searching (and thanks to a tip I saw in a comment of another SO question - sorry, I lost the link...) on how to better read xcode crashes (https://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1), I found the issue to be in the Mapbox software I was using (https://github.com/mapbox/mapbox-navigation-ios) and not in my code at all.....

The issue of inconsistency boiled down to the location changing from the Simulate Location and the push notification coming in as/at the 'destination' point (when the 'current location' and 'destination location' were the same, MapBox software was coming up with a nan).

I fixed that by doing a check for nan (.isNaN) though got another crash a bit later.....

Now, I've updated the SDK and am fighting other issues (one being that we no longer get the voice - another that the Simulate Location seems to not be working..... AARRGGHH!) but at least the particular issue in the question is answered - it was in the library!



Related Topics



Leave a reply



Submit