1
以下は、私が構築しようとしているUITableViewCell
構造体です。動的コンテンツ用のtableViewCellのAutolayout
上記のタイトルは、私が自動レイアウトせずにUIを生成することができる午前array.Currentlyから来ています。しかし、この場合、私は動的なサイズのセルの高さを得ることができません。
//Second cell
case 2:{
UIView *thirdContainer = [[UIView alloc]initWithFrame:CGRectZero];
[cell.contentView addSubview:thirdContainer];
UILabel *titleLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(8, 8, 220, 20)];
titleLabel2.text = @"Features:";
[thirdContainer addSubview:titleLabel2];
NSDictionary *thirdDict = @{@"thirdContainer":thirdContainer,@"titleLabel2":titleLabel2};
[thirdContainer setTranslatesAutoresizingMaskIntoConstraints:NO];
NSArray *thirdContainerWdt = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[thirdContainer]|" options:0 metrics:nil views:thirdDict];
NSArray *thirdContainerHT = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[thirdContainer]|" options:0 metrics:nil views:thirdDict];
[cell.contentView addConstraints:thirdContainerWdt];
[cell.contentView addConstraints:thirdContainerHT];
// Without Autolayout
int x;
int y = 10;
for (int i=0; i<_featuresArray.count; i++) {
if (i%2==0) {
x = 8;
y = y + 18;
}else{
x = 200;
}
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(x, y,160, 18)];
lbl.text = _featuresArray[i];
[thirdContainer addSubview:lbl];
}
}
とテーブルビューのセルの高さは以下のように管理されている - -
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==2) {
if (_featuresArray.count==1||_featuresArray.count==2) {
return 50;
}else{
float ht = _featuresArray.count;
ht = ht*25;
return ht;
}
}else{
return UITableViewAutomaticDimension;
}
}
は、どのように私はそのようにこれらのラベルをレンダリングする自動レイアウトを使用することができます以下
は、私がこれまでに行うことができるよ何でありますセルの高さは自動的に管理されますか?他のすべてのセルについては、viewDidLoad
にエイメイションされた行の高さを使用しています。ラベルの制約を追加する方法を理解することはできません。
_myTableView.estimatedRowHeight = 168.0;
_myTableView.rowHeight = UITableViewAutomaticDimension;
私は私が見るにUILabelsの制約を作成する方法を理解することができload.Howeverしなかったことを行っているあなただけのviewDidLoad –
に固定してセルの高さを設定するので逃したと思います。 – icodes
申し訳ありませんが、私は動的な制約を伴いながら快適ではありません –