2015-08-19 3 views
1

Я пытаюсь авторизовать ячейку таблицы с автозапуском. Но, похоже, TableView игнорирует ограничения по высоте.Как использовать масонство autolayout UItableviewCell height

UIImage и UILabel в UITableViewCell:

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     self.icon = [[UIImageView alloc] init]; 
     [self.contentView addSubview:self.icon]; 
     [self.icon mas_makeConstraints:^(MASConstraintMaker *make) { 

     make.top.equalTo(self.contentView).with.offset(10); 
     make.left.equalTo(self.contentView).with.offset(10); 
     make.width.offset(70); 
     make.height.offset(70); 
//   make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10); 
     }]; 
     self.icon.backgroundColor = [UIColor redColor]; 

     self.customText = [[UILabel alloc] init]; 
     self.customText.text = @"xx11dragon"; 
     self.customText.backgroundColor = [UIColor yellowColor]; 
     self.customText.numberOfLines = 0; 
     self.customText.lineBreakMode = NSLineBreakByCharWrapping; 
     [self.contentView addSubview:self.customText]; 

     [self.customText mas_makeConstraints:^(MASConstraintMaker *make) { 

      make.top.equalTo(self.contentView).with.offset(10); 
      make.left.equalTo(self.icon.mas_right).with.offset(10); 
      make.right.equalTo(self.contentView.mas_right).with.offset(-10); 
//   make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10); 

     }]; 

В UITableViewClass:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    _cell.title.text = [dict objectForKey:@"title"]; 
    _cell.customText.text = [dict objectForKey:@"content"]; 
    [_cell setNeedsLayout]; 
    [_cell layoutIfNeeded]; 
    CGSize size = [_cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; 
    NSLog(@"%f",size.height); 


    return size.height + 1; 
} 

size.height равна 0.0f

UITableViewCell высота равна UIImage или UILabel дно + 10px, как установить дно?

ответ

1

В iOS 8 вы можете использовать этот подход.

self.tableView.estimatedRowHeight = 100.0; 
self.tableView.rowHeight = UITableViewAutomaticDimension; 
Смежные вопросы