ios - UITableViewCell subclass, wrong height until scroll -


i have custom uitableviewcell in use uiimageview. want cell able resize height according aspect ratio, based on imageview width, keep getting these constraints problems:

"<nslayoutconstraint:0x7ffe13c14130 'uiview-encapsulated-layout-height' v:[uitableviewcellcontentview:0x7ffe117fb920(44)]>", "<nslayoutconstraint:0x7ffe13c15090 v:|-(0)-[uiview:0x7ffe13c11c10]   (names: '|':uitableviewcellcontentview:0x7ffe117fb920 )>", "<nslayoutconstraint:0x7ffe13c150e0 v:[uiview:0x7ffe13c11c10]-(0)-[uibutton:0x7ffe117e8110]>", "<nslayoutconstraint:0x7ffe13c15190 v:[uibutton:0x7ffe117e8110(30)]>", "<nslayoutconstraint:0x7ffe13c151e0 v:[uibutton:0x7ffe117e8110]-(0)-[uiview:0x7ffe13c11d00]>", "<nslayoutconstraint:0x7ffe13c15910 uiview:0x7ffe13c11d00.height == uiview:0x7ffe13c11c10.height>", "<nslayoutconstraint:0x7ffe13c15960 v:[uiview:0x7ffe13c11d00]-(0)-[uibutton:0x7ffe13c0b000]>", "<nslayoutconstraint:0x7ffe13c159b0 uibutton:0x7ffe13c0b000.height == uibutton:0x7ffe117e8110.height>", "<nslayoutconstraint:0x7ffe13c15a50 v:[uibutton:0x7ffe13c0b000]-(0)-[uiview:0x7ffe13c11df0]>", "<nslayoutconstraint:0x7ffe13c15aa0 uiview:0x7ffe13c11df0.height == uiview:0x7ffe13c11c10.height>", "<nslayoutconstraint:0x7ffe13c15af0 v:[uiview:0x7ffe13c11df0]-(0)-|   (names: '|':uitableviewcellcontentview:0x7ffe117fb920 )>" 

my constraints are

    [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[s1(>=10)][pictureview][s2(==s1)]|" options:0 metrics:nil views:dict]];     [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[s3][markasfavorite(==30)][s4(==s3)][markfordeletion(==markasfavorite)][s5(==s3)]|" options:0 metrics:nil views:dict]];     [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|[s1][s3]|" options:0 metrics:nil views:dict]];     [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|-10-[pictureview][s3]|" options:0 metrics:nil views:dict]];     [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|[s2][s3]|" options:0 metrics:nil views:dict]];     [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:[pictureview]-10-[markasfavorite(==30)]-10-|" options:0 metrics:nil views:dict]];     [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:[pictureview]-10-[markfordeletion(==30)]-10-|" options:0 metrics:nil views:dict]];     [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:[pictureview][s5]-10-|" options:0 metrics:nil views:dict]];     [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:[pictureview][s4]-10-|" options:0 metrics:nil views:dict]];       photoheight = [nslayoutconstraint constraintwithitem:pictureview                                                attribute:nslayoutattributeheight                                                relatedby:0                                                   toitem:nil                                                attribute:nslayoutattributenotanattribute                                               multiplier:1                                                 constant:(5*pictureview.frame.size.width)/16];       [self.contentview addconstraint:photoheight]; 

these constraints added once, in updateconstraints method of cell subclass. in "drawrect" method update "photoheight" constant , force layout update.

the result: @ first load, cells pretty bad, after scroll update height , expected. think problem "photoheight" constant not being updated when cell first loaded, don't know how fix taking consideration depends on imageview's width. can solve problem?

i attached screenshots: before scrolling before scrolling

after scrolling after scrolling

as can see in first screenshot, image gets out of cells contentview, because cell small image...but, after scrolling cells resized correctly. want them resized beginning, not after scrolling.

i figured out causing version of this.

i assigning values late in cell's lifecyle. dequeued cell, setting property cell's model, , deferring assignment of uiviews (uilabels, in case) until layoutsubviews(). ended causing issue dimensions calculated before set text of uilabels.

i recommend doing display setup @ time dequeue cell:

override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) {     var cell = tableview.dequeuereusablecellwithidentifier("mycustomcell", forindexpath: indexpath) mycustomcell     cell.setupallthethings(mytabledataz[indexpath.row])     return cell } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -