Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 6 view controller showing blank screen with autolayout

I'm trying to use view controller that I decided to use auto layout for. Before I used auto layout, the view showed normally like how I intended it to during runtime. But I decided to switch to auto layout (because after all, bigger iPhones are coming), and even after setting it up, getting no issues at all, and seeing that the app scaled well to the iPhone size in IB; I still have a blank screen. To prove it, here are pictures:

Xcode 6 shot.[][1]

iOS Simulator shot. Note that the navigation bar and tab bars are showing.

So why is this happening? I added the constraints in the square view, and it gracefully scaled to the iPhone view in Interface Builder. If you also look at the sidebar, the alerts for auto layout errors are not present. And IB is rendering everything. But why is the simulator blank?

And yes, I connected all the elements to be code correctly. I verified. And yes, I have code that puts text in a label. Here it is, in the 'viewDidLoad()' method:

override func viewDidLoad() {
    super.viewDidLoad()
    self.titleLabel.text = "Hello, World!"
}

And I will reemphasise: the app worked before I did auto layout. For this build, I deleted all the elements, relocated them, reconnected them, and added tweaked the view with auto layout unit IB rendered it correctly. But I'm getting different results here.

Please help me. Oh, and sorry for the massive images, I can't figure out how to shrink them.

EDIT: I've gone through and used the view debugger, and tried to capture the view hierarchy to look for clipping or occlusion. Funny enough, the view debugger shows the content properly, and there wasn't any clipping or occlusion that I saw. When I tried to show frames in the simulator though, it didn't show anything. I'm starting to think that this is a simulator bug. Currently, I'm using Xcode 6 beta 6.

like image 206
Adil Patel Avatar asked Sep 08 '14 14:09

Adil Patel


2 Answers

I recreated the issue by adding a collection view to a standard view controller and this seems to be the problem:

Constraints added when selecting "Add suggest constraints"

enter image description here Having Xcode add suggested constraints gives you this, which causes the view to not show up.

It is aligning the view's left and right to the layout guides (which doesn't seem to be right)

You will have to manually add spacing constraints to your view.

This is what you want:

enter image description here

like image 54
Myron Slaw Avatar answered Oct 09 '22 15:10

Myron Slaw


Try turning on the assistant editor and use Preview while tweaking your constraints.

Screenshot
(source: mattknott.com)

like image 39
Knotty Avatar answered Oct 09 '22 17:10

Knotty