Search code examples
iosswiftios8uipopovercontrolleruipopover

Popover not showing the content


I'm just trying to display a ViewController as a Popover, this is a small part of a big iPad application, and I've being trying to display the content with no success.

Testing with this simple scenario

The result is empty

The worst thing is that if I create the same scenario in an empty/new project, it's works! The two View Controllers showed in the Image1 are completely new, I created those after tried to add a simple Popover action in one of my views I'm using in the App...which was not working. I tried with Clean and Build the Project more than once...just in case, but the same result. It's just not working in this specific project.

The two view controllers don't have Classes associated yet, I'm just trying to open the View2 when I click on the Button.

I appreciate your comments if I'm missing something really basic in this scenario.

(Adding more details)

I tried a different thing with the restrictions as you can see in the last two images, now I can see "something", but it's not respecting the positions.

Testing with Different Restrictions Result in the simulator


Solution

  • There are some problems in your constraints.

    • The Label should have 3 constraints: left (Leading), right-to-the-text-field (Trailing) and top (Top Space):

    Constraints of the label

    The width and height are not needed because they are automatically set from the intrinsic content size of the label text ("Label"). IMPORTANT: When you add the constraints be sure that they are absolute, not margin related (to understand the difference read this blog post iOS8 Layout Margins).

    • The Text Field should have the following constraints: width and distance-from-top (Top Space):

    enter image description here

    Note that the second ("Leading Space") is the same of the "Trailing Space" of the label, not an additional one (the constraints are 5 in total).

    You have to explicitly set the width of the text field (134 in my example) because otherwise the intrinsic content size will be set (and it is near to 0 because the text field is initially empty). The height is set correctly from the intrinsic size (calculated from font height, also if text is empty).

    NOTE:

    My answer implies some important Autolayout concepts. I advice you to study the Apple documentation to better understand them.

    Hope this helps