UITableViewAutomatic Gap Restrictions?

I am trying to use UITableViewAutomaticDimension , but it is difficult for me to get the full cell width and the correct height without causing problems with NSLayoutAutomaticSizeConstraint... If I turn off automatic size limits on a cell, this is not the full width.

enter image description here

I have two buttons with horizontal and vertical restrictions for representing content. They have a vertical limit between them, and each button has a height limit.

If you disable AutoResizingMask , I get a cell that is not full width. If I leave it, I get layout restrictions, but everything displays correctly.

How can I get the behavior I'm looking for?

 translatesAutoresizingMaskIntoConstraints) ( "<NSLayoutConstraint:0x7f856b169650 V:[UIButton:0x7f856b16a510'+(null)'(50)]>", "<NSLayoutConstraint:0x7f856b173dd0 UIButton:0x7f856b16a510'+(null)'.top == UITableViewCellContentView:0x7f856b16bfa0.topMargin>", "<NSLayoutConstraint:0x7f856b173e70 UITableViewCellContentView:0x7f856b16bfa0.bottomMargin == UITextField:0x7f856b16c4f0.bottom>", "<NSLayoutConstraint:0x7f856b174520 V:[UIButton:0x7f856b16a510'+(null)']-(8)-[UITextField:0x7f856b16c4f0]>", "<NSLayoutConstraint:0x7f856b182a10 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f856b16bfa0(66)]>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7f856b169650 V:[UIButton:0x7f856b16a510'+(null)'(50)]> 

It actually looks like this: the width is set

 - (CGSize)intrinsicContentSize { return CGSizeMake(320, 66); } 

If I do not set my own size for the content, I get no width or height.

+5
source share
3 answers

edit: These are definitely two height restrictions. Try removing one or lowering the priority.

+2
source

AutoresizingMask on = allows parents of this view to set appropriate masks.

AutoresizingMask off = Do not allow parents of this view to set appropriate masks. I want to do it myself.

If you create views in IB, their autoresizingMasks defaults to No.

If you create views in code, their auto-resistor masks are set to Yes by default.

The fact that you get a cell that is not full width (or, indeed, any behavior change) when you turn off AutoresizingMask means that the probability that the parent (in the view hierarchy) of the cell or table captures and sets restrictions (which is not what you want to).

Now the reason I think you get this cell not full width is caused by an annoying default in IB when you drag between view elements to set constraints, instead of binding constraints from above, from below, etc. IB connects him with the edge (different).

Therefore, you need to select your restrictions from the "Document Context":

Document outline

And then select your border-bound constraints one by one:

Constraint closed

And make sure the "Relative to field" option is not checked.

Constraint open

If you use the "Summary Constraints" tab in the lower right corner of IB (second from left), you can cancel the "Field Restriction" when creating restrictions:

Constraints summary

Constraints optn

+1
source

I had a similar problem with this:

 func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } 

He threw me a journal about β€œfailure to meet restrictions,” but there was no restriction in it, so I added an evaluation chart for HeightForRowAtIndexPath:

 func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } 

And he fixed

+1
source

Source: https://habr.com/ru/post/1207939/


All Articles