0

I've been asked to convert a UITableViewCell with a height determined by autolayout to, in some cases, a table view cell with zero height. What's the most efficient way to do this? I have tried disabling all autolayout constraints related to vertical positioning and height in the appropriate cases, but I still end up with a non-zero height table view cell and the following message:

2016-06-02 12:36:06.781 [1336:556232] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.

and so I'm getting this:

non-zero table view cell height

I saw this issue discussed in an existing highly useful SO post (iOS8 - constraints ambiguously suggest a height of zero), but I already do have have an autolayout constraint to container bottom from a 'spacer view', which is the resolution suggested there. In particular I use a spacer view of 0 height with layout constraints to have 0 distance from the view to top, bottom, and both leading and trailing.

enter image description here

enter image description here

Above you can see the two relevant vertical-related views. I've also checked that everything is wired up to my outlets for when I active/disactivate constraints.

What else should I be troubleshooting here?

Community
  • 1
  • 1
helloB
  • 3,472
  • 10
  • 40
  • 87
  • did you override the estimatedHeight delegate method ? – Akhilesh Sharma Jun 02 '16 at 16:49
  • @AkhileshSharma yes, but that returns a non-zero number for all cases, and I was hoping I wouldn't have to add logic there. – helloB Jun 02 '16 at 16:49
  • it never a good option to add a logic inside estimated height method though, the best to have this kind of stuff is alter your datasource and use begin and end update methods to make alteration on the view – Akhilesh Sharma Jun 02 '16 at 16:52
  • @AkhileshSharma Originally instead of height zero I was changing the row count, but I was asked to take this approach instead. – helloB Jun 02 '16 at 16:56
  • You should not be disabling the constraints then, instead have an outlet for height of the container and set it as per your needs when required. – Akhilesh Sharma Jun 02 '16 at 16:59
  • @AkhileshSharma I tried that but it had layout constraint conflicts and broke them in favor of not having a 0 height – helloB Jun 02 '16 at 17:00
  • you need to change the priority of the constraint then. Look into the compression and hugging – Akhilesh Sharma Jun 02 '16 at 17:01
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/113664/discussion-between-hellob-and-akhilesh-sharma). – helloB Jun 02 '16 at 17:04
  • Could be share you cell design? For now what i can suggest you is for constraint like TopSpace, VerticalSpace and BottomSpace set constant value as less than or equal (<=) the if you are setting fixed height to any element then set its constant value to less than equal, and return the cell height 0 for the indexPath you want to make it of height 0. – Bharat Modi Jun 06 '16 at 05:41

0 Answers0