Summary
I have an iOS project that comes from the Xcode Master-Detail template. However, I am encountering a "view hierarchy is not prepared for the constraint" error. The table cells in the master view have a tap gesture recognizer that segues to the detail view when a cell is pressed. On the second tap, the program crashes with the aforementioned error. Other issues related to this seem to happen when generating constraints from code, however I have been using the Interface Builder exclusively, so I haven't been able to find another case just like mine.
The detail view contains a UITableView and a UIToolbar. What's causing this? Thanks for your help.
Xcode output
The view hierarchy is not prepared for the constraints: <NSLayoutConstraint:0x16d79980 V:[_UILayoutGuide:0x16d791b0]-(44)-[UITableView:0x1729b000]>
When added to a view, the constraints 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.
*** Assertion failure in -[UIView _layoutEngine_didAddLayoutConstraint:roundingAdjustment: mutallyExclusiveConstraints:]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Impossible to set up layout with view hierarchy unprepared for constraint.'
Constraints on the tableview in the detail controller:
Constraints on the toolbar in the detail controller:
I was getting this. Upon checking constraints for "all" size classes, I had a top space constraint that I didn't create (or didn't remember crewing anyway) and that I didn't want. It was ghosted and I couldn't delete it.
Clicking the "install" checkbox to install this constraint for all size classes un-ghosted the constraint and then I was able to delete it, resolving the crash.
Related
I am making an iPad app that, among other things contain a view in which to set options.
This "Options" View has two container-views, each holding a TableView with two different kinds of options in them, and switches to turn these options on or off.
The problem is that when I try to make a button from my main ViewController that will open the options view, I get the following error:
Screenshot of signal SIGABRT error
with this in the output:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-c2d-Su-6Id" from storyboard "Options", but didn't get a UITableView.'
I don't know why the underlying function [UITableViewController loadView] is used, as I do not expect my Options-view to be a TableView - the tables are in container views.
I am using different storyboards, and a segue to a storyboard reference to present the Options View modally. I have tried deleting both the button, the segue and the Storyboard reference, replacing them with new ones, and renaming my ViewController.swift file, and all the references to it, with no luck
I have also tried looking for other solutions here on the site, but I have had no luck, and I begin to fear it might be because of the tableViews in the containerViews...
I am quite new to learning swift and Xcode, so please keep your explanations simple to follow, and assume that I am completely incompetent :-)
I'm guessing you probably added a Container View, which automatically places a "child" view controller onto the Storyboard, and then simply changed the Class of that child VC to UITableViewController --- which, as you found out, doesn't work.
To use a table view controller as the child, add your Container View, then add a normal UITableViewController to the Storyboard. Then, Ctrl-Drag from the Container View to the new table view controller and select Embed from the popup menu.
I'm following the SwiftExample from JSQMessagesViewController but attempting to place the ChatViewController into a container view controller. It works as expected except that the text input toolbar does not show at the bottom.
I have experimented with sizing and looking at the hierarchy debug view to see if the input toolbar may be hidden offscreen, but it does not appear to exist. The toolbar is part of the JSQMessagesViewController xib file. Why would it not show?
UPDATE:
I see that jsq_configureMessagesViewController explicitly removes the inputToolbar from the view. If I comment out that line as an experiment I get the toolbar to appear, however it then fails with an error regarding having the wrong parent in the view hierarchy.
So obviously there are things I do not yet understand about input views and the view hierarchy. This thread seems related:
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',
and for what it's worth here is my storyboard showing the container:
Storyboard diagram
The problem seems to be unique to the current development branch. Reverting to an earlier release seems to work.
Terminating app due to uncaught exception:
'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ViewController" nib but the view outlet was not set.
I am getting this error in xcode 6. I know how to set view outlet in xcode 5 or below version (go to connection inspector drag outlet radio button to file's Owner then it pop with a view and then click on view sets the outlet) but view popup is not comming in xcode 6 (beta). Is it a xcode 6 bug or it has different way to set an outlet.
Can anyone help please?
It means you have a view controller, but you have not set the view outlet. In interface builder, right click on the view controller, and outlet and action popup will appear. Find the view outlet, and drag it to the topmost view in the views list.
I had this problem and basically it was due to a button being assigned to an outlet (which i did not need) and and action that I was actually using. To resolve this type of issue, you need to make sure that your buttons are correctly assigned and get rid of any outlets that you do not need or that you may have added by mistake.
It happens to me when you changed ui element in storyboard, didn't clean them completely. Just right click on the top view controller, and it will show which one should be deleted
I like to create my views as standalone Xib files then instantiate them and add as subviews.
So, when working with a UINavigationBar, I expected to be able to do the same thing, first creating my custom view - from the Xib - then adding it as a custom view to the UIBarButtonItem:
UIBarButtonItem *anItem = [[UIBarButtonItem alloc] initWithCustomView:_myCustomView];
Then adding to the nav bar:
self.navigationBar.topItem.rightBarButtonItems = #[ anItem, anotherItem ];
So far so good.
Now, _myCustomView uses Auto Layout (AL) and I thought this would be no problem. Not the case. I've tried just about everything. Nothing has worked. I even tried adding the custom view as a subview of the controller that has the navigation bar. Thinking that as siblings in the view hierarchy, AL would treat it as a regular view outside the UINavigationBar.
That didn't work either. The controller's updateViewConstraints was called but never applied. The view's initial frame stayed at CGRectZero. It's as if AL sees that the view is on top of a UINavigationBar, even as a sibling, and decides it doesn't need laying out.
Of course, I've tried bringSubviewToFront, translatesAutoresizingMaskIntoConstraintstranslatesAutoresizingMaskIntoConstraints, and so on. The latter gave the lovely:
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Auto Layout still
required after executing -layoutSubviews. MyNavigationBar's
implementation of -layoutSubviews needs to call super.'
So, the question is, has anyone loaded a custom view with AL from a Xib, and successfully set this as a customView on a UIBarButtonItem? If so, how?
Looks like a duplicate of iOS Autolayout and UIToolbar/UIBarButtonItems
UIBarButtonItems do not inherit from UIView, so using auto-layout based custom views within them might not be fully supported. Sounds like you have to do the pre auto layout thing until the issue is resolved. I would suggest filing a bug.
EDIT: By the pre auto layout thing, I mean manipulating the frame of your views directly.
In storyboards using a static content tableview. I've added a tableview cell. In it I've added a view and a label. When I assign the view as the cell's backgroundView (ctrl+click & drag from the cell to the view) I get the following error at run after loading the tableview.
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITableViewCell's implementation of -layoutSubviews needs to call super.'
If I remove the association, it runs without issue.
Has anyone had any experience with this error?
I'm going to make a guess that is the one rare time where a view is treated as being included twice in a view hierarchy. When layout is performed, it goes through the normal view heir achy and lays out the view, but then (or before that) it lays out the background view hierarchy as well. This would HAVE to result in a layout error.
The solution? Growl at apple and ignore it. Disconnect the view from the backgroundView property and just deal with it as a view. This works for me. I don't see any great advantage in connecting it.