Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the autolayout constraints in a xib are ignored #395

Closed
hariseldon78 opened this issue Apr 27, 2016 · 7 comments
Closed

the autolayout constraints in a xib are ignored #395

hariseldon78 opened this issue Apr 27, 2016 · 7 comments

Comments

@hariseldon78
Copy link
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.

@mtnbarreto
Copy link
Member

mtnbarreto commented Apr 27, 2016

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
Copy link
Contributor Author

hariseldon78 commented Apr 27, 2016

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
Copy link
Member

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

@hariseldon78
Copy link
Contributor Author

sure, i'll do that after dinner

@hariseldon78
Copy link
Contributor Author

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
Copy link
Contributor Author

hariseldon78 commented Apr 27, 2016

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
Copy link
Member

mtnbarreto commented Apr 28, 2016

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.

hariseldon78 added a commit to hariseldon78/Eureka that referenced this issue Apr 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants