Skip to content

the autolayout constraints in a xib are ignored #395

@hariseldon78

Description

@hariseldon78
Contributor

i'm trying to create a custom cell providing a xib and a setup method.
My cell has all the autolayout constraints needed to adapt to the quantity of text in the labels, but the library uses the height closure to compute cell height (forcing me to recalculate what the constraints are alredy doing, and to keep the closure updated every time i tweak the xib)

that is wrong, it should use the constraints and dynamically size the cells.

Activity

mtnbarreto

mtnbarreto commented on Apr 27, 2016

@mtnbarreto
Member

I think your cell.height should return UITableViewAutomaticDimension.

from row setup method...

cell.height = { UITableViewAutomaticDimension }

Could you confirm that this works for you?

I'm not sure if you also need to update tabeView's estimatedRowHeight:

    public override func viewDidLoad() {
        super.viewDidLoad()
        tableView?.estimatedRowHeight = UITableViewAutomaticDimension
    }

I'm considering that your cell constraints are properly set up.

hariseldon78

hariseldon78 commented on Apr 27, 2016

@hariseldon78
ContributorAuthor

umm.. i didn't know about it, anyway it's not working, i'm still getting an autogenerated constraint that reduce my cell height:
<NSLayoutConstraint:0x7af931e0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7af4cee0(65)]>

mtnbarreto

mtnbarreto commented on Apr 27, 2016

@mtnbarreto
Member

@hariseldon78 Could you share the code by uploading a project to reproduce the issue?

hariseldon78

hariseldon78 commented on Apr 27, 2016

@hariseldon78
ContributorAuthor

sure, i'll do that after dinner

hariseldon78

hariseldon78 commented on Apr 27, 2016

@hariseldon78
ContributorAuthor

testEurekaCustomCell copy.zip

Ok, here is the project. My original cell is "ResizingLabelCell", but i made another simpler cell with just a label. The label is configured with "0 lines" and "Word wrap", so it should expand to the size of the text. Also, if you look with "View debugging -> capture view hierarchy" you'll see that the constraint which set the height of the label is consistent with the content, but then there is the "encapsulated layout height" which ruins everything...

hariseldon78

hariseldon78 commented on Apr 27, 2016

@hariseldon78
ContributorAuthor

Hey, I think i've got something: if i modify the Core.swift at row 707 like this:

public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    form[indexPath].updateCell()
    return form[indexPath].baseCell
}

and comment the willDisplayCell at row 629 (so it isn't called twice), all the layout is perfect!

2016-04-28_01-16-37

Why? I have no idea. Just another of the thousand quirks of UITableView i guess.. Could you please give me some feedback about if this patch is acceptable or maybe it breaks something else?

mtnbarreto

mtnbarreto commented on Apr 28, 2016

@mtnbarreto
Member

I don't remember why i put these code into willDisplayCell, apparently it works perfectly after deleting these method and adding the .updateCell() invocation from cellForRowAtIndexPath so go ahead and make a pull request.

Apparently we don't even need the following linetableView?.estimatedRowHeight = UITableViewAutomaticDimension customization.

added a commit that references this issue on Apr 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @hariseldon78@mtnbarreto

        Issue actions

          the autolayout constraints in a xib are ignored · Issue #395 · xmartlabs/Eureka