maxsokolov / TableKit

Type-safe declarative table views.
MIT License
706 stars 74 forks source link

How to get rid of AutoLayout warning when using TableKit #89

Open bernikovich opened 5 years ago

bernikovich commented 5 years ago

Hello. How should I implement constraints to get rid of these warnings. I see it comes when table view requests cells for index path:

screen shot 2019-01-21 at 5 05 56 pm

I setup cells like subview.top == cell.contentView.top, subview.bottom == cell.contentView.bottom.

maxsokolov commented 5 years ago

Hey @bernikowich

First of all, let's make sure that this is not a problem with TableKit itself. Do you have this warning with regular UITableView setup (without TableKit)?

I setup cells like subview.top == cell.contentView.top, subview.bottom == cell.contentView.bottom.

Are you sure that you have all required constraints? What about leading/trailing (left/right) constraints?

bernikovich commented 5 years ago

@maxsokolov Looks like I found where my issue comes from. I should say I create UI in code. So I implemented such controller in the demo project. In this case if minimum height of cell is more then 44 OS prints warning logs. Steps:

  1. Create cell in code with constraints subview.top = contentView.top + 25 and subview.bottom = contentView.bottom - 25.
  2. Set estimatedHeight for cell 100 - it should be enough since 25+25=50<<<100.
  3. TableDirector receives cell with height 44 for the first time. screen shot 2019-01-21 at 6 29 17 pm
  4. When layoutIfNeeded called we have constraint for height equal to 44, while it cannot be satisfied because our minimum height for contentView is 50.
bernikovich commented 5 years ago

Screenshot I attached previously is incorrect. I should attach screenshot from TablePrototypeCellHeightCalculator. When TablePrototypeCellHeightCalculator dequeues cell it has default height. For cells created in code it's 44.

bernikovich commented 5 years ago

Related SO question: https://stackoverflow.com/questions/32172250/uitableview-auto-resizing-row-constraint-breaking-mysteriously-on-iphone-6plus

bernikovich commented 5 years ago

Looks like it related more to UIKit itself. I don't know why UITableView dequeues cell for indexPath with 44pt height and not estimated height. When you use IB it creates cells with bigger size.