Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

ios - Could not instantiate class named IBNSLayoutConstraint

I'm using XCode6 beta and trying out Swift. When I put some auto layout constraints in a view controller the app crashes with the following error: Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named IBNSLayoutConstraint'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're getting this error because you've set a constraint to an IBOutlet that is removed at runtime. This happens when you set the constraint to be a placeholder in Interface Builder. Since the constraint is removed, when it goes to unarchive it, it throws an error saying it can't do so.

There are two ways to correct this.

Method 1

  1. Right-click on your Storyboard > Open As > Source Code
  2. In the opened storyboard xml, search for placeholder="YES".
  3. You'll find constraints that are set to be removed at runtime. Remove the placeholder attribute from the constraint, save and close.
  4. Run the app and your problem should be fixed.

Method 2

  1. Find the constraint that's causing your problems in Interface Builder. Uncheck the Placeholder option in the GUI. This should be one of the constraints that's set to an IBOutlet in the ViewController that's causing your crash.

Interface Builder attribute editor showing the Placeholder option checked.

This is what it should look like:

Interface Builder attribute editor showing the Placeholder option unchecked.

Alternative

Assuming you actually want the constraint to be a placeholder, then you'll need to remove any referencing outlets. To do this, select the constraint that you wish to be a placeholder. Then open the connections inspector (the button furthest to the right that looks like this: (->) ) and then remove any referencing outlets that may exist on that constraint.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...