내 제한에 따라 내 UITableViewCell
높이를 설정할 수 없습니다.cellForRowAtIndexPath 다음에 높이 조정 UITableViewCell
각 셀에 내 UITableView
UILabel
높이가 고정되어 있지 않으며 높이가이 UILabel
에 달려 있습니다.
레이블의 내용을 업데이트 한 후에 셀에 프레임을 설정하려고했지만 아무 일도 일어나지 않습니다.
//On my controller
- (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CommentCell";
CommentCell *commentCell = [tView dequeueReusableCellWithIdentifier:CellIdentifier];
if (commentCell == nil) {
commentCell = [[CommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Comment *comment;
if (commentsArray.count > indexPath.row) {
comment = [commentsArray objectAtIndex:indexPath.row];
}
[commentCell setComment:comment];
[commentCell setCommonFields];
currentCellheight = commentCell.contentLabel.frame.size.height + 40;
DDLogInfo(@"Current Cell Height: %f", currentCellheight);
return commentCell;
}
//On my custom Cell (CommentCell.m)
-(void)setCommonFields {
if (self.comment != nil) {
self.contentLabel.text = self.comment.content;
self.contentLabel.numberOfLines = 0;
CGSize maximumLabelSize = CGSizeMake(self.contentLabel.frame.size.width, FLT_MAX);
CGRect expectedLabelRect = [self.contentLabel.text boundingRectWithSize:maximumLabelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:nil context:nil];
CGRect newFrame = self.contentLabel.frame;
newFrame.size.height = expectedLabelRect.size.height;
self.contentLabel.frame = newFrame;
}
}
나는 heightForRowAtIndexPath
방법 높이 감사 설정도 시도했지만이 방법은 내 레이블이 업데이트됩니다cellForRowAtIndexPath
전에 라고 아래에 내 코드를 검색 할 수 있습니다.
이 문제를 해결할 더 이상의 아이디어가 없습니다.
미리 감사드립니다.
마법을, 당신은'heightForRowAtIndexPath' 방법에있는 당신의 높이를 결정하고이를 반환해야합니다. 'cellForRowAtIndexPath'에 셀의 높이를 설정할 수 없습니다. – Adam