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.
Related
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.
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.
I am new for IOS development , and I try to use UIcollectionView to show the photo.
I create a xib file from New file -> iOS -> User Interface -> View , and add a Collection View like the following picture.
But I got the following error log when it crash.
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '-[UICollectionViewController loadView]
loaded the "AITLocalGridViewController" nib but didn't get a UICollectionView.'
And it seems didn't call viewDidLoad
I have search for some information , some information indicated that I dint not connect the collection view in xib file
But I don't understand what it mean.
Could some one help me and teach me what to do ?
Make sure that you have connected UIcollectionview IBOutlet with “collectionview “ that you declared in your program. And also you should make delegate&data source connection(For making this, click on th Uicollectionview in the xib. Select Connection Inspector. Where you can see delegate and datasource.By pressing ctrl button drag and connect it to File’s Owner.)
Just remove the view in Storyboard and use the UICollectionView as direct child.
Make sure UICollectionViewController's "view" outlet is set to a UICollectionView. Setting the "collectionView" to a UICollectionView is not enough for a UICollectionViewController.
At the risk of stating the obvious, also make sure that the UICollectionView is inside a UICollectionViewController. This can be overlooked when you do something like adding an embedded view into your project, where the default embedded view is the standard view controller.
I'm still new to objective -c. I have everything else working but I just can't wrap my head around this login screen atm.
I can log in but after that, my app crashes and I get this error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
But without the login screen, it works fine. My storyboard looks like this:
Could someone lend a hand?
The problem is not really inside your login screen, but in the MasterViewController. With some breakpoints, you should see that your present controller is allocated, it's viewDidLoad is probably called.
But inside some method of the tableView's delegate implementation (probably cellForRowAtIndexPath:) your code crashes. Make sure to have a correct implementation of the tableView's methods, using a identifier for cell in your XIB/Storyboard (or registering with registerClass:forCellReuseIdentifier: method ,etc.
This link should help you with the problem: Why am I getting an error about being unable to dequeue when my UITableView tries to load?
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.