곧 여기에 내 자신의 질문에 대답 :
원래 내가 높이 계산이
tableView:cellForRowAtIndexPath:
방법에 연결하고, 다른 곳에서 이동 될 수 없음을 확신했다. 구조 조정의 무리와 함께, 나는 그 물건을 거기에서 꺼내어
tableView:heightForRowAtIndexPath:
에 넣을 수 있었다. 그것은 모든 것을 해결한다. ,
// Inside tableView:cellForRowAtIndexPath:
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = self.numberOfTextRows;
// numberOfTextRows is an integer, declared in the class
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGSize theSize = [theObject.theStringToDisplay sizeWithFont:[UIFont systemFontOfSize:18.0f] constrainedToSize:CGSizeMake(265.0f, 9999.0f) lineBreakMode:UILineBreakModeWordWrap];
// This gets the size of the rectangle needed to draw a multi-line string
self.numberOfTextRows = round(theSize.height/18);
// 18 is the size of the font used in the text label
// This will give us the number of lines in the multi-line string
if ((indexPath.section == FIXED_HEIGHT_SECTION) || (self.numberOfTextRows < 2)) {
return 44;
// 44 is the default row height; use it for empty or one-line cells (or in other table sections)
} else {
return theSize.height + 16;
// 16 seems to provide a decent space above/below; tweak to taste
}
}
당신이 적절한 셀 높이를 계산하는 더 정확한 방법을 생각할 수있는 경우 : 자동 높이 조정 세포가 작동하도록하려고 다른 사람들을위한
, 여기에 도움이 될 몇 가지 코드입니다 나는 모든 귀이다. :)
을 다음과 같은
tableView:heightForRowAtIndexPath:
의 구현 내부의tableView:cellForRowAtIndexPath:
전화를했다 직각 높이를 18로 나누고 다시 곱하면됩니다. 그러나 그것보다 거의 똑같습니다. –글쎄, 첫 번째 부분은 얼마나 많은 행이 필요한지 알아내는 것입니다. 그래서'cell.textLabel.numberOfLines'을 올바르게 설정할 수 있습니다; 설정하지 않으면 모든 것이 한 줄에 인쇄됩니다. 하지만 네,'self.numberOfTextRows' 대신 마지막 비트에서'theSize.height'를 사용할 수있을 것 같습니다. – Triz
명확성과 단순화를 위해 대답을 편집했습니다. 정말 잘 작동합니다. – Triz