xcode - Unable to simultaneously satisfy constraints in uitableviewcell with uiimageview -
first, system automatically removes proper constraint working expected understand how make code better. uitableview working in ios 8.0 automatic mode , not implement heightforindexpath method.
the uitableview displays images in uitableviewcells , trying add ratio constraint uiimageview image displayed correctly. seems working expected there might don't understand (order of method called or constraint not given @ right moment not sure).
below part of code can have at. image width , height stored in database , used set constraint before downloading image.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { postimagetableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifierpostimage]; if (cell == nil) { cell = [[postimagetableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifierpostimage]; } // adding image [cell.imagepost setimagewithurl:[nsurl urlwithstring:[[self.mydata objectatindex:indexpath.row] valueforkey:@"image"]] placeholderimage:[uiimage imagenamed:@""]]; // adding constraint [cell setconstraints:[[[self.mydata objectatindex:indexpath.row] valueforkey:@"imagewidth"] doublevalue] withheight:[[[self.mydata objectatindex:indexpath.row] valueforkey:@"imageheight"] doublevalue]]; return cell; }
the setconstraints method of postimagetableviewcell custom class here. trying achieve remove old constraint given previous cell , add new 1 new image in next cell ... understand logs seems not that. mixing constraints or have give ratio number cleaner?
- (void)setconstraints:(double)width withheight:(double)height { int fullwidth = [[uiscreen mainscreen] applicationframe].size.width; [self.imagepost removeconstraint:self.imageconstraint]; self.imageconstraint = [nslayoutconstraint constraintwithitem:self.imagepost attribute:nslayoutattributewidth relatedby:nslayoutrelationequal toitem:self.imagepost attribute:nslayoutattributeheight multiplier:(max(width,(fullwidth-20))/height) constant:0.0]; [self.imagepost addconstraint:self.imageconstraint]; }
error message. seems not ratio constraint given ... again, displays correctly in simulator/device i'd understand doing wrong.
unable simultaneously satisfy constraints. @ least 1 of constraints in following list 1 don't want. try this: (1) @ each constraint , try figure out don't expect; (2) find code added unwanted constraint or constraints , fix it. (note: if you're seeing nsautoresizingmasklayoutconstraints don't understand, refer documentation uiview property translatesautoresizingmaskintoconstraints) ( "<nslayoutconstraint:0x7fb80cbac720 v:|-(11.5)-[custlabelwithpadding:0x7fb80cb66240'jul 20 - 18:39'] (names: '|':uitableviewcellcontentview:0x7fb80cb8bfd0 )>", "<nslayoutconstraint:0x7fb80cbac7c0 v:[custlabelwithpadding:0x7fb80cb66240'jul 20 - 18:39'(23)]>", "<nslayoutconstraint:0x7fb80cbac580 v:[custlabelwithpadding:0x7fb80cb66240'jul 20 - 18:39']-(11.5)-[custlabelwithpadding:0x7fb80b90d8e0'tr']>", "<nslayoutconstraint:0x7fb80cbac8c0 v:[custlabelwithpadding:0x7fb80b90d8e0'tr'(>=34.5)]>", "<nslayoutconstraint:0x7fb80cbac840 v:[custlabelwithpadding:0x7fb80b90d8e0'tr']-(1)-[custlabelwithpadding:0x7fb80cba83e0'rr']>", "<nslayoutconstraint:0x7fb80cbac9e0 v:[custlabelwithpadding:0x7fb80cba83e0'rr'(>=34.5)]>", "<nslayoutconstraint:0x7fb80cbac910 v:[custlabelwithpadding:0x7fb80cba83e0'rr']-(1)-[uiimageview:0x7fb80cba8a20]>", "<nslayoutconstraint:0x7fb80cbaca30 v:[uiimageview:0x7fb80cba8a20]-(1)-[uiview:0x7fb80cba8c20]>", "<nslayoutconstraint:0x7fb80cbacc00 v:[uiview:0x7fb80cba8c20(50.6)]>", "<nslayoutconstraint:0x7fb80cbacb80 v:[uiview:0x7fb80cba8c20]-(11.5)-| (names: '|':uitableviewcellcontentview:0x7fb80cb8bfd0 )>", "<nslayoutconstraint:0x7fb80cbb0130 h:[uiimageview:0x7fb80cba8a20(352)]>", "<nslayoutconstraint:0x7fb80cbb2080 uiimageview:0x7fb80cba8a20.width == 1.65647*uiimageview:0x7fb80cba8a20.height>", "<nslayoutconstraint:0x7fb80cbabf60 'uiview-encapsulated-layout-height' v:[uitableviewcellcontentview:0x7fb80cb8bfd0(392.5)]>" ) attempt recover breaking constraint <nslayoutconstraint:0x7fb80cbb2080 uiimageview:0x7fb80cba8a20.width == 1.65647*uiimageview:0x7fb80cba8a20.height>
i cleaned code bit width available 375-20*1.15. image height 212.5 (number stored in database) final ratio 352/212.5 = 1.65647... seen in error message. other constraint working fine think used cell without images , have no error message them.
actually, if try math missing 0.1 in end ... minimum tick being half point system not find same height sum in end. replaced ratio constraint height constraint , making sure giving proper height (no "strange number")
[self.contentview removeconstraints:self.imageconstraints]; double ratio = (max(width,(fullwidth-20*multiplier))/height); double newheight = floor((fullwidth / ratio) / 0.5 + 1) * 0.5; nsdictionary *viewsdic = @{@"imagepost":self.imagepost}; self.imageconstraints = [nslayoutconstraint constraintswithvisualformat:[nsstring stringwithformat:@"v:[imagepost(%f)]",newheight] options:0 metrics:0 views:viewsdic]; [self.contentview addconstraints:self.imageconstraints];
as can see newheight modified have in end "nice" number system like. removed constraints issues. same height of 50.6 well. using same equation made sure send 51 , not 50.6.
Comments
Post a Comment