2016-08-10 2 views
0

スクロール、私はセルの高さと各indexPathのViewControllerでテーブルビュー

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    PFBubbleData *dataModel = (PFBubbleData *)self.dataSource[indexPath.row]; 
    PFBubbleLayout *layout = dataModel.layout; 
    return layout.bubbleHeight; 
} 

での行の設定dynamitcの高さをキャッチしてからセルを取得するときに、レイアウトがミックスです

(各サブビューはすでにので、ここで、getMethodで作成した直接サブビューを追加)、contentViewにサブビューを追加し、セルを作成するときに、セルキューデータモデルの魔女との更新には、レイアウトモデルに

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    PFBubbleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PFBubbleCell"]; 
    [cell updateViewWithData:self.dataSource[indexPath.row]]; 
    return cell; 
} 

が含まれています

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ 
    LOG_METHOD 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     self.contentView.translatesAutoresizingMaskIntoConstraints = NO; 

     self.contentView.backgroundColor = [UIColor colorWithRed:0.224 green:0.671 blue:1.000 alpha:1.000]; 

     [self.contentView addSubview:self.faceImageView]; 
     [self.contentView addSubview:self.containerView]; 
    } 
    return self; 
} 

最後に、私はときに私のセットアップデータモデルのセルにサブビューを更新し、石工レイアウトサブビューに

-(void)updateViewWithData:(id)dataEntity { 
    LOG_METHOD 
    self.dataModel = (PFBubbleData*)dataEntity; 
    //update the subeViewFrame is Needed after the data changed 
    [self.faceImageView setImage:self.dataModel.avatarImage]; 
    [self setupFrameAndConstraints]; 
} 

を使用石工のレイアウトが、それはこのように表示され

-(void)setupFrameAndConstraints { 
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { 
    make.edges.equalTo(self).insets(UIEdgeInsetsMake(0, 0, 0, 0)); 
}]; 

if (self.dataModel.bubbleDirection == PFBubbleDirection_Other) { 
    //    self.avaterImageView.frame = CGRectMake(self.dataModel.layout.board_margin, 
    //              self.dataModel.layout.board_margin, 50, 50); 
    //    self.containerView.frame = CGRectMake(CGRectGetMaxX(self.avaterImageView.frame) + self.dataModel.layout.board_margin, 
    //              CGRectGetMinY(self.avaterImageView.frame), 
    //              self.dataModel.layout.contentSize.width, 
    //              self.dataModel.layout.contentSize.height); 

     [self.faceImageView mas_updateConstraints:^(MASConstraintMaker *make) { 
      make.top.equalTo(self.contentView.mas_top).offset(contentMargin); 
      make.left.equalTo(self.contentView.mas_left).offset(contentMargin); 
      make.width.mas_equalTo(@(50)); 
      make.height.mas_equalTo(@(50)); 
     }]; 

     [self.containerView mas_updateConstraints:^(MASConstraintMaker *make) { 
      make.top.equalTo(self.faceImageView.mas_top); 
      make.left.equalTo(self.faceImageView.mas_right).offset(contentMargin); 
      make.width.mas_equalTo(self.dataModel.layout.contentSize.width); 
      make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-contentMargin); 
     }]; 
    }else if(self.dataModel.bubbleDirection == PFBubbleDirection_Self){ 
    //    self.avaterImageView.frame = CGRectMake(self.frame.size.width - self.dataModel.layout.board_margin - 50, 
    //              self.dataModel.layout.board_margin, 50, 50); 
    // 
    //    self.containerView.frame = CGRectMake(CGRectGetMinX(self.avaterImageView.frame) - self.dataModel.layout.board_margin - self.dataModel.layout.contentSize.width, 
    //              CGRectGetMinY(self.avaterImageView.frame), 
    //              self.dataModel.layout.contentSize.width, 
    //              self.dataModel.layout.contentSize.height); 

     [self.faceImageView mas_updateConstraints:^(MASConstraintMaker *make) { 
      make.top.equalTo(self.contentView.mas_top).offset(contentMargin); 
      make.right.equalTo(self.contentView.mas_right).offset(-contentMargin); 
      make.width.mas_equalTo(@(50)); 
      make.height.mas_equalTo(@(50)); 
     }]; 

     [self.containerView mas_updateConstraints:^(MASConstraintMaker *make) { 
      make.top.equalTo(self.faceImageView.mas_top); 
      make.right.equalTo(self.faceImageView.mas_left).offset(-contentMargin); 
      make.width.mas_equalTo(self.dataModel.layout.contentSize.width); 
      make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-contentMargin); 
     }]; 
    } 
    [self setNeedsLayout]; 
    [self layoutIfNeeded]; 
} 

を下回っている。 enter image description here enter image description here

テーブルをスクロールするとログが表示される

enter image description here

答えて

0

[OK]を、私は使ったことがない石工が、テーブルビューには、細胞を再利用し、再利用のセルに-(void)updateViewWithData:(id)dataEntityを呼び出すことを忘れドント:このように。だから、あなたはそれを2番目(または3番目)の時間と呼びます。

したがって、制約をもう一度設定します。

は、たとえば、あなたが初めて -(void)updateViewWithData:(id)dataEntityを呼び出したときに真に設定されたID layoutDoneに名前を付け、セルが再利用されたときに、再びこの関数を呼び出すドントことができます(フラグを設定します。

希望はこのことができます。

0

私はこの問題はcellForRowAtIndexPathをうそ。あなたは

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    PFBubbleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PFBubbleCell"]; 
    if(cell) { 
     cell = [[PFBubbleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PFBubbleCell"]; 
    } 
    [cell updateViewWithData:self.dataSource[indexPath.row]]; 
    return cell; 
} 
としてデータソースメソッドを宣言試みることができると思います
関連する問題