Xcode Interface Builder 9.1 Collection View Cells have too small "expected height" - interface-builder

Recently, I encountered a problem with the Interface Builder which I failed to solve. I'm using a UICollectionViewController and whenever I add a Cell it immediately shows a orange rectangle (indicating a auto-layout update). Updating the frame/cell doesn't change anything. The warning associated with the orange marking reads "Expected: height=Y, Actual: height=X" where Y is always exactly X-100. That is: When I set a custom cell height of 193, it says "Expected: height=93". This happens no matter which size I enter.
The problem with this is that I have many difficulties with the subviews and their constraints. For instance, if I add a subview with the constraint to keep the same height as the cell, it will be shown as 93 (the expected height), even though my cell should be 193. Layouting becomes impossible.
I tried adding a new cell, same issue. I tried removing every subview and re-adding them, nothing.
Any ideas are highly welcome.
Thank you very much!

Solution found ! (Xcode 9.2)
The bug seems to only happen when you try to embed the UICollectionViewController in a Container View in the storyboard. The workaround is to remove the segue while you set your constraints, and re-add the segue once your constraints are well set.
I also think that setting UICollectionViewController size as Freeform could be responsible of the bug. If so, try to set constraints before changing the size.
Hope this helps !

I'm not sure if this solved it, but the warning and issue disappeared once I did the following:
Select the CollectionViewController in Interface Builder and set the size to freeform and make the height larger, large enough to show all your template cells. (Plus: maybe refresh the views). That solved the issue for me.

In my case, I have added two collection view cell, withing collection view Controller.Only setting the view controller to free form wont help us. Need to update the size, to get rid of the warning.
updating collection view cell frames, wont help us. Warning will be continuously changing its length.
I tried to work without considering the warning, as I have set my collection view cell size programmatically and it does working as expected.

I think it's just a strange bug
I delete the collectionViewController in SB, then create a new one, the problem disappear

This is a common bug with Interface Builder. I don't know the exact cause, but I believe it's something to do with placing collection views inside arrangement views that do not have an exact size. I've seen it when putting them in scroll views, stack views and container views.
There is a simple fix, although I believe this to be a bug in IB that ought to be corrected by Apple rather than hacking around it. The solution (for me at least - your mileage may vary!) is to place the collection view inside an ordinary UIView and pin its edges to it, then place that parent view in the position that you wanted your collection view with all the constraints it required.
I usually found that there were actually no auto layout issues at run-time, which is why I believe this to be purely an Interface Builder bug.

Related

Swift : Auto Layout Issue

I edited my view with auto layout. I clicked add missing constraints. I'm working 4 inch screen on mainstoryboard. Everything looks good for 4 inch, but not the other iphone screens. I tried some ways like someone did, but I didn't fix it.
Snapshot :
This screen from iPhone 6s. Something going wrong for picker view, google ad and the others.What shoul I do? By the way sorry for black lines.
My view and UIs are here. How should I do the constraints for each every one of them? I'm really new for iphone layout. If you explain step by step basically, I really appreciate for that.
Sorry but clicking add missing constraints it's never the ideal solution, you really should understand how and which constraints you really need for your layout.
If you have clicked add missing constraints now you probably have a lot of constraints, you need to check for example your picker view which constraints it has and fix one of them or more.
So IMHO now you have two ways: post here, updating your post, the full list constraints you have for one object at least and we can try to help you, of course, I'm the first; the second solution it's clear all constraints and add one by one, understanding each rules: it could be boring at first but it will be really helpful believe me.
I would begin adding your layout constraints from the top of your view controller. You can add the constraints manually by right click dragging from the target object to another object. Most of the time, it is necessary to add at least two constraints to a view, one constraint that modifies the x coordinate of the object and another constraint that modifies the y coordinate of the object.
I would recommend using the leading/trailing space constraints and the top/bottom space constraints for all of your objects that you want to be hugging the view controller. After you make these constraints between the controller and the objects, add constraints between two objects. If all of the lines are blue or orange, you probably have sufficient and satisfactory constraints.

A popup, "Failed to automatically update constraints" pops up in Xcode 6.3.1

When I added a couple of controls in my viewcontroller in storyboard and click
Resolve Auto Layout Issues -> Reset to Suggested Constraints.
The following popup appears and I cannot perform auto layout constraints.
Though, when I remove the Prototype Cell (which has a couple of labels and an imageview) from my tableview then auto layout works fine. Any thoughts?
Edited:
And manually adding constraints to individual elements work fine as well. After manually setting the image view inside prototype cell, the auto layout has started working fine without popping up that popup. So, maybe, sometime, it is hard for auto layout to figure out all these constraints itself.
Try clearing constraints before resetting them, this has worked for me before.
I had the same problem when using prototype cells in a UITableView and some other views in a UIViewController.
My solution was to select all the elements in the prototype cell and see if these had red or orange markers (constraint conflicts/problems). These elements I cleared the constraints for and afterwards I had no problem telling the entire view to "Reset to Suggested Constraints".
Obviously, Interface Builder has a problem resetting embedded table content constraints.
Actually . If you import different storyboard from another Xcode project. This is not possible to avoid problem. My personal advice is create a new UIViewcontroller or stroyboard. And step by step add items. But. I did not do this.
I lived three times. In fact When I saw this message. I was configuring tableview or UITableviewcell. At the end of the story I have fixed my problem. But There is no gold key for issue. I will explain as much as possible.
for All Views in View Controller select Clear Constraints
If you are using tableview or collection view. please delete.
I assume. there are label, button and scrollview on the project. Please add missing constraints. If you leave problem again. You need to delete any of them.
for All Views in View Controller Reset to Suggested constraints.
If you don't leave problem again. PERFECT. If there is a reverse situation
for All Views in Second View Controller select Clear Constraints
delete any of item. Select add missing constraints again.
Continue to try the third and fourth steps. Until you find the faulty objects.
I'll try to help you if you submit your project.
Good luck .
Following Solution work for me.
Actually initially i used Free-from storyboard of size 600 into 900 that time i was getting this error. so i deleted that storyboard and again drag and drop element and make connections, then i solved issue.
I have faced same problem with Xcode 6. In my MainViewController I have a tableview with custom TableviewCell. In Interface builder itself I have taken taken 2 labels on tableview cell.
When I try to add constraints it gives me error. I did remove prototype cell in tableview and worked with nib with customCell. Be careful while working with custom tableViewCell.
Let me know if you need any additional information.
I had same issue last evening, After many try and error i found that it was just a corrupt ViewController. I created a new ViewController2 with the same aspects, then applied constraints to the ViewController2, and it worked! Still not sure why exactly the other one had issues.
I had some problem with Xcode 7. I solved it very simple. I cleared constraints -
Reset to Suggested Constrains
, then applied -
Add Missing Constrains.
This has worked for me.

Split View Controller showing only one view (Xcode 6)

I'm trying to get the split view controller working properly but apparently there's a bug in there or I'm missing something.
First of all, I've started a blank OSX Obj-C application, and in the Storyboard I've dragged the split view controller. Next, I've linked the segues from the main window controller to the split view and added two labels.
http://i.imgur.com/dlFObaF.png
When I build the project, it shows only the second page. Not to mention strange window size in the final build.
http://i.stack.imgur.com/IqRqr.png
I've tried everything.
This occurs in both vertical and horizontal split view.
Any suggestions?
I had the same issue myself today, but it's just the split line wasn't initiated properly.
To see, this, once you run your app, move your mouse toward the edge of the window and drag it, you will now see another view emerging.
To my best knowledge, I do not know how to fix this in IB or in code. Apparently NSSplitViewController does not have a property like UISplitViewControllerAutomaticDimension. Would appreciate if someone can contribute to this.
Edited: Found an answer via another thread. Basically, try to add some constraints to the subviews inside each view and that should prevent the size of a view to be zero. In my toy example, adding margin constraints to my buttons worked out well.

Problems with NSTabView autolayout (view based NSTableViews inside tabs)

I have an NSTabView which has 5 tabs. Each tab contains an NSTableView (which, as default, is nested in NSScrollView). This is all loaded from a xib file with autolayout turned on. I'd like each table to fully occupy it's respective tab. Using autolayout I select each tab and carefully setup the NSScrollView so that it snaps its top, bottom, lead, and trailing edges to superview. After I do this for the 5 tabs, I'll resize the xib to give it a test. When I cycle back through the tabs, some stay snapped to the superview and some do not. There appears to be some sort of order to this but it is beyond what I can explain.
What's really frustrating is that sometime this will run okay, and sometimes it will crash because of unsatifyable constraints. For now I am using springs/struts but I like autolayout and would like to get it working.
I am afraid that it is the nesting of the tables inside scroll views which is causing the issues.
If you lay this out your own nib, you should be able to reproduce it.
I am hopeful that this can be solved by adding NSLayoutConstraints at runtime, if OSX is anything like iOS's autolayout. Using IB you cannot assing constraints to anythign other than super and sibling (no cousins). This can be done at runtime.
I am hoping someone out there has encountered this issue and has a solution.
Why do the constraints in the layout show a fixed constant instead of auto? Could that be it?
You mentioned cousin constraints, I believe you can add in the in IB if you select two views in the document outline on the left hand side and then add a constraint. I'm unable to pick any two views in IB if I'm using the main window but I can do it in the document outline.
Lastly, you mention it will run okay sometimes but not others - and if that's the case it sounds like something else is adding constraints. Instruments should have a template for tracing constraints, if you can reproduce it you may get a clue to what is introducing the incompatible constraint.

IB builder or programmatically draw?

What do you advise? should I programmatically draw my textfields, labels, images or should I use IB?
Would it make any difference? I have scrolling issues (bit jerky) but not something I cannot live without!
I would use IB to help maintain the app. Jerky performance is usually a result to memory management issues and not specific to IB. IB just does the object creation and sets common properties, so do it in code, or in IB the end result is the creation of objects and setting of properties.
ok. problem solved. you were right and wrong regarding the IB...
to explain myself:
I was loading my cell from a nib file.
The trick and thanks goes to this site: http://iphoneincubator.com/blog/tag/dequeuereusablecellwithidentifier
i forgot to set my cell identifier to the nib file so i was creating the cells every time they were scrolled off the screen!
so tip!
When you load from nib ALWAYS put the right identifier in the "identifier" place!!!
thanks to nolimitsdude who actually pointed to the right way!!

Resources