ios 实现 cell 的动态高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

  Message *msgObj = _items[(NSUInteger) indexPath.row];
  NSString *msg = msgObj.content;
  CGFloat maxWidth = CGRectGetWidth(tableView.bounds);

  CGFloat msgCellWidth = maxWidth - MessageCellAvatarPadding * 2 - AVATAR_HEIGHT - MessageCellPadding-20;
  CGFloat height = [MsgCell heightForMessage:msg constrainedToWidth:msgCellWidth];

  return height+20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  MsgCell *msgItemCell = [tableView dequeueReusableCellWithIdentifier:kMsgCellId forIndexPath:indexPath];
  Message *msg = self.items[(NSUInteger) indexPath.row];
  [msgItemCell setMessage:msg];
  return msgItemCell;
}
posted @ 2015-10-30 11:20  damnbird  阅读(243)  评论(0编辑  收藏  举报