0

I have a custom tableviewcell using Autolayout, design in xib file.

design:

enter image description here

CustomTableViewCell.h: @property (weak, nonatomic) IBOutlet UIView *customView; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintRatio;

it's works fine in the tableview.

what I want to do is update CustomView's Ratio programmatically, before the tableviewcell display.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ CustomTableViewCell *customCell = [self.mainTableView dequeueReusableCellWithIdentifier:@"customCell"]; customCell.constraintRatio.constant = 2; [customCell setNeedsUpdateConstraints]; [customCell setNeedsLayout]; [customCell layoutIfNeeded]; return customCell; }

but the cell's ratio remain 1 after that. what did i do wrong or what did i miss? thanks for any suggestion.

superwave
  • 180
  • 1
  • 8

1 Answers1

0

problem solved.

I misuse customCell.constraintRatio.constant. which should be multiplier.

but multiplier is readonly. so the only way to do my work is delete the constraint and add new one

after doing so, all works fine.

reference: auto layout modify multiplier of constriaint programmatically

Community
  • 1
  • 1
superwave
  • 180
  • 1
  • 8