4

I actually have a problem with auto layout. How can I fix the problem ? I don't understand what is it and how to fix it.

Description

I'm trying to resolve multiple problems :

  • Having a UITableView #1 with two subclass of UITableViewCell : HeaderCell and ListSongsCell.
  • Having a UITableView #1 with a dynamic cell height.
  • Having a UITableView #2 as a subview of ListSongsCell.
  • Having a UITableView #2 with a dynamic height (based on the number of row). The type of cell for UITableView #2 are just basic (44px height).

Basically i'm trying to do an inception of tableview here.

Here's an image of what i'm expecting :

http://imageshack.us/a/img703/9374/i7wn.png

Actually I can get UITableView #1 to have a dynamic cell height using HeaderCell. All the constraints of HeaderCell are defined in the storyboard, it's basically just a UIImageView.

Problem

When I want to insert a ListSongsCell in UITableView #1 I got the following log :

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) 
(
    "<_UIScrollViewAutomaticContentSizeConstraint:0x8a8e820 UITableView:0x9275c00.contentHeight{id: 199} == -150.000000>"
)

Will attempt to recover by breaking constraint 
<_UIScrollViewAutomaticContentSizeConstraint:0x8a8e820 UITableView:0x9275c00.contentHeight{id: 199} == -150.000000>

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.

Basically I know something is wrong with the constraints on the storyboard but I don't really understand what and why. In my mind the flow are like that :

  1. Trying to get ListSongsCell height
  2. Trying to get ListSongsCell ContentView height
  3. Trying to get UITableView #2 height

What's the problem here ? How I can solve this errors using constraint in storyboard ? Do you understand what's happen exactly ?

Why I'm trying to solve that ?

I know I can easily do that in others ways like :

  • Insert multiple cell instead of inserting one cell who contain a tableview
  • Just having a button who drop down a tableview
  • Disable constraint and it based on frame (old way).

But I'm really curious about this problem, i'm sure I can have a final smooths result with nested tableview working.

Sources

Here's the sources I used to help me accomplish this problem.

Sample Project

Check out this sample project on GitHub who reproduce the problem : https://github.com/hefgi/TableViewInTableViewCell

Feel free to raise any questions or issues you run into (you can open issues on GitHub/commits or post comments here).

Community
  • 1
  • 1
hefgi
  • 484
  • 5
  • 14

0 Answers0