【发布时间】:2016-07-18 10:09:13
【问题描述】:
我有一个使用 Autolayout 的自定义 tableviewcell,在 xib 文件中设计。
设计:
CustomTableViewCell.h:
@property (weak, nonatomic) IBOutlet UIView *customView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintRatio;
在表格视图中可以正常工作。
我想做的是在 tableviewcell 显示之前以编程方式更新 CustomView 的 Ratio。
-(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;
}
但此后单元格的比率仍为 1。 我做错了什么或者我错过了什么?感谢您的任何建议。
【问题讨论】:
标签: ios autolayout constraints tableviewcell