Search code examples
uitableviewios7autolayoutuipopovercontrollerautoresizingmask

UITableViewCellContentView width is always zero according to the autoresizing mask (only on iOS 7)


I'm using the Auto Layout approach of dynamic cell height as described in Using Auto Layout in UITableView for dynamic cell layouts & variable row heights. This works so far. Now I'm presenting my UITableView in a UIPopoverController what also works. Now to the interesting part: I'm presenting this popover from different view controllers. On the first view controller everything works as expected. If I switch to second view controller, which also provides this popover, the popover is completely empty (even without separator line!) and I get the following error:

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7a706fa0 H:|-(8)-[UILabel:0x7a707760]   (Names: '|':UITableViewCellContentView:0x7a707ba0 )>",
    "<NSLayoutConstraint:0x7a707060 H:[UILabel:0x7a707760]-(8)-|   (Names: '|':UITableViewCellContentView:0x7a707ba0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x7a706970 h=--& v=--& H:[UITableViewCellContentView:0x7a707ba0(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7a707060 H:[UILabel:0x7a707760]-(8)-|   (Names: '|':UITableViewCellContentView:0x7a707ba0 )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

Now we pay attention to this part:

"<NSAutoresizingMaskLayoutConstraint:0x7a706970 h=--& v=--& H:[UITableViewCellContentView:0x7a707ba0(0)]>"

It says that the width of the UITableViewCellContentView is zero according to the autoresizing mask. But the same code work on another view controller before. And the popover should be independent of my settings in a view controller. I tried to replicate the behavior in another project but I can't. This also only appear on iOS 7. On iOS 8 everything is working fine. I also tried to go away from auto layout and then the content is displayed (but not in the way I want). The only option I can come up with is to go back to spring and struts ... If you want I could provide my code in C#, but I left it out to make the question more readable.

What could be the reason for this? Has anyone experienced something like this?


Solution

  • After searching for a day for the reason it was the default mistake one could make. Because I had the controller before not in a popover the following line of code was still there:

    myViewControllerInPopup.View.TranslatesAutoresizingMaskIntoConstraints = false;
    

    I had this on the view controller which instantiated the popover. Remove this line and everything work as expected.