2016-07-18 13 views
0

xibファイルでデザインするAutolayoutを使用してカスタムtableviewcellを作成しました。テーブルビューセルは、プログラムでAutoLayoutの更新制約を使用します。

デザイン:

enter image description here

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残ります。 何が間違っていたのですか?何が欠けていましたか?ご意見ありがとうございます。

答えて

0

問題を解決しました。

私は誤って使用しますcustomCell.constraintRatio.constant。これは乗数でなければなりません。

しかし、multiplierは読み取り専用です。ので、私の仕事を行うための唯一の方法は、は、制約を削除し、新しい1つを追加した後、

のすべてをうまく動作します。

参照: auto layout modify multiplier of constriaint programmatically

関連する問題