Xcode 6..0.1 fails to compile storyboard - xcode6

I just upgraded my Xcode to 6.0.1 and I am not able to compile anymore. Xcode build is failing with following error:
nwi_state: registration failed (1000000)
2014-09-18 12:46:28.977 Interface Builder Cocoa Touch Tool[19152:359412] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7fb2cb5b5800 UIImageView:0x7fb2cb5893e0.centerY == UITableViewLabel:0x7fb2cb5a8950.centerY>
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
2014-09-18 12:46:28.978 Interface Builder Cocoa Touch Tool[19152:359412] *** Assertion failure in -[UITableViewCellContentView _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:], /SourceCache/UIKit_Sim/UIKit-3318/NSLayoutConstraint_UIKitAdditions.m:558
Command /Applications/Xcode.app/Contents/Developer/usr/bin/ibtool failed with exit code 255

Based on this note in the log:
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
Add a symbolic breakpoint:
-[UIView _viewHierarchyUnpreparedForConstraint:]
Also you might just want to clear the constraints for the view involved.

Related

Initiating Phone Call with a button gives issues when view controller is embedded with Navigation controller

I have a View controller with a button that initiates phone call and it works fine. But when i embed this view controller with a Navigation Controller it gives me this error in console " Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"",
""
)
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful."
I don't understand why i get this error because i haven't added any constraints yet. Can someone help?

Debugging programmatic autolayout constraints

I've created my view controller's view entirely in code by adding subviews and constraints (using the CocoaPod PureLayout). It actually looks/ functions exactly how I want it to, but xcode yells at me saying one of the constraints is wrong and it removes it. How can I tell which UIViews the bad constraints are attached to? I have a lot of subviews and I can't figure it out from context. When working with constraints in interface builder, you can name the UIView and that's what gets printed to the debug console- but I can't find a way to accomplish this through code.
Looking at the apple docs: https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/ResolvingIssues/ResolvingIssues.html#//apple_ref/doc/uid/TP40010853-CH17-SW14
They say:
"It may be obvious which view has the problem; if it is not, you may find it helpful to use the NSView method _subtreeDescription to create a textual description of the view hierarchy.
Important: The _subtreeDescription method is not public API; it is, however, permissible to use for debugging purposes"
Is this what I'm looking for? How do I make use of a private API?
Starting with the iOS 8 SDK, there is now an identifier property on NSLayoutConstraint. Note that this property has existed privately (Apple-only) since iOS 7, but now that it is public in iOS 8, you are allowed to make use of it even when running on iOS 7.
Using this property, you can easily set a unique short description to your constraints to aid in debugging. For example, using PureLayout:
NSLayoutConstraint *constraint = [label autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:imageView];
constraint.identifier = #"Label Left Padding";
// ...or using PureLayout v2.0+:
[[label autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:imageView] autoIdentify:#"Label Left Padding"];
// PureLayout v2.0+ also supports a block-based version to set an identifier to many constraints at once:
[UIView autoSetIdentifer:#"Constraints to position image view" forConstraints:^{
// ...a bunch of PureLayout API calls here that create constraints...
}];
Then, you will see this identifier printed next to the constraint in the console if there is a constraint exception.
One other handy debug tool:
Apple has a very handy category on UIView (declared in UIView.h) named UIConstraintBasedLayoutDebugging that includes a method:
- (NSArray *)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis;
You can call this method on any view, passing either Horizontal or Vertical axis (since constraints in each axis are independent), and get a list of all the constraints that affect the position and size along that axis. Note that Apple says this should be used for debugging only - never ship code that uses this API!
UIWindow also has a private instance method _autolayoutTrace to dump a string that shows the overall view hierarchy, including views that are ambiguous. Just use it from the console after setting a breakpoint after you see the constraint exception. You can also trap any autolayout exceptions using a symbolic breakpoint "UIViewAlertForUnsatisfiableConstraints".
Check out Facebook's Chisel too: https://github.com/facebook/chisel

NSInvalidUnarchiveOperationException: Could not instantiate class named NSLayoutConstraint

I am very new to this. I followed Apple's tutorial step by step for the iPhone project "HelloWorld". I ran it in the iPhone 5.0 simulator and it crashed:
2012-11-02 14:46:06.782 HelloWorld[9880:c07] * Terminating app due
to uncaught
exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate
class named NSLayoutConstraint'
* First throw call stack:
(0x14a2052 0xea2d0a 0x144aa78 0x144a9e9 0x32f7d7 0x32f9af 0x32f6b7 0x23036d 0xd7e2c 0xd83a9 0xd85cb 0x38a73 0x38ce2 0x38ea8 0x3fd9a
0x10be6 0x118a6 0x20743 0x211f8 0x14aa9 0x138cfa9 0x14761c5 0x13db022
0x13d990a 0x13d8db4 0x13d8ccb 0x112a7 0x12a9b 0x1fed 0x1f15 0x1)
terminate called throwing an exception(lldb)
Can someone please tell me what went wrong? I'm using Xcode 4.5.
By default, when you create a new iOS project in Xcode 4.5, your storyboard or XIB is set to use Autolayout, which is a new feature in iOS 6.0. The NSLayoutConstraint class is part of the Autolayout system, and it doesn't exist in older versions of iOS.
If you want to deploy your app to an older version of iOS, you need to change your storyboard or XIB to not use Autolayout. It's a checkbox in the File Inspector:
Your Xib file (Interface builder file) contains AutoLayout elements, which iOS 5 does not support.
In Xcode, go to your .xib file(s), and for each one, turn off AutoLayout. There should be a checkbox on the left hand side saying "Use AutoLayout", uncheck it and try again. (This is under the first tab in the left hand side inspector, when you have File's owner) selected.
I stumbled into this error when I was working on an older project I wanted to update. I had selected the "Use Autolayout" checkbox to start working with constraints, but had forgotten to update my Deployment Target setting to iOS 6.
You need to run it in iPhone 6.0 simulator. Your error:
* Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint' *
Suggests that you are using autolayout, which only works on iOS 6.

presentViewController: crash on iOS <6 (AutoLayout)

This is a weird crash I am getting. The crash happens when I press a button that goes to a certain ViewController. The line which it crashes on is:
DestinationInformationViewController *info = [[DestinationInformationViewController alloc] init];
[info setModalTransitionStyle: UIModalTransitionStyleCrossDissolve];
[self presentViewController:info animated:YES completion: nil]; // CRASHES HERE
[info release];
The crash trace is:
*** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint'
*** First throw call stack:
(0x3758288f 0x35287259 0x37582789 0x375827ab 0x3153d54d 0x3153d6bb 0x3153d423 0x314ce001 0x3143c3c7 0x31319c59 0x3128fc17 0x3129a267 0x3129a1d5 0x3133959b 0x31338367 0x84091 0x374dc3fd 0x31271e07 0x31271dc3 0x31271da1 0x31271b11 0x31272449 0x3127092b 0x31270319 0x31256695 0x31255f3b 0x33c9822b 0x37556523 0x375564c5 0x37555313 0x374d84a5 0x374d836d 0x33c97439 0x31284cd5 0x82bb3 0x71200)
terminate called throwing an exception(gdb) Could not instantiate class named NSLayoutConstraint
NOTE: This crashes on my iPhone 4 iOS 5.1 but not on my iPhone 4S iOS 6 Beta 2
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:
Open your xib.
Go to the File Inspector tab.
Find the Interface Builder Document section on the right toolbar.
Uncheck the Use Auto Layout option.
I had the same problem when I downloaded new XCode update and IOS6 SDK. Here's how I solved it:
Select the Interface builder file (whether xib or storyboard file) where your error occurs.
In assistant editor on the right in XCode, select the first tab from the left, and there is a checkbox for option "Use Autolayout" like on the screenshot above.
Uncheck the checkbox.
Nagaraja asks "How to resolve the same if we are not using xib? I ran into exactly this problem. I created a controller with a xib, and then I decided to remove the xib file. The crash did not go away. The problem was that I needed to implement
- (void) loadView
in my controller class. Once I implemented this method the problem got solved.
Another possible reason for a crash with presentViewController is having something in the nib connected to a variable that is no longer there - the variable either having it's name changed or it was deleted.

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController loadView] loaded the nib but no view was set

From what I understand of the SDK, this exception is raised when the bindings in IB are not proper. But in my case, the view is loaded fine for the first two times. I then move back from the view using the NavigationController.
The third time when I try to open the view, I get this exception. The fact that it opens correct the first two times, means the bindings are correct and the view is fine! But then why does it fail the third time?
Any pointers?
Thanks.
I am calling -initWithNibName:bundle: to initialize the view which is created in IB. Not calling the -loadView method.
It is not getting garbage collected. AFAIK, there is no garbage collection in iPhone SDK and we need to dealloc stuff explicitly.
It seems that you have not bind the view to it's file owner.
For fixing this thing go open the xib which you are using in this ViewController. Right Click on your main view and then bind this view to the File Owener's view property.
You may be running low on memory, which forces the system to send out low-memory messages to instantiated view controllers. The default implementation of -didReceiveMemoryWarning clears out the view member variable. In theory, then next time the view is required, it should be re-instantiated, but you may have overridden something that's preventing that.
The view object might be going out of scope, and getting garbage collected.