0
伙计。 我有UITableView与不同的单元格,我有代码,它计数高度。在一个项目中,它完美的工作,但在第二个它返回高度等于0. 这可能是什么原因造成的? 我的代码:与sizeWithFont方法的神秘麻烦
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
CGFloat cellWidth = 320.0f;
CGSize size = [cell.textLabel.text sizeWithFont:cell.textLabel.font constrainedToSize:CGSizeMake(cellWidth, CGFLOAT_MAX) lineBreakMode:cell.textLabel.lineBreakMode];
CGFloat height = size.height;
NSLog(@"Height: %f", height);
return height;
}
对于正确的答案 - 第一个heightForRowAtIndexPath被调用,然后是cellForRowAtIndexPath。为什么OP已经看到这个工作以前仍然是一个谜。 – Till 2012-01-14 21:28:40
谢谢,我想,这个问题更难。 – werbary 2012-01-15 08:21:45