0
我正在使用heightForRowAtIndexPath和sizeWithFont来计算单元格的高度。在3或4行文本之后,包含文本的标签会越过单元格视图的顶部和底部。从0到3行的任何内容都会正常增长和收缩。UITableView单元格内容将通过单元格图形
我无法找到细胞在高处有一个硬顶的位置。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSArray *array = [sectionsArray objectAtIndex:indexPath.section];
NSDictionary *dictionary = [array objectAtIndex:indexPath.row];
id key = [[dictionary allKeys] objectAtIndex:0];
NSString *keyString = [NSString stringWithFormat:@"%@", key];
NSString *keyContents = [NSString stringWithFormat:@"%@", [dictionary objectForKey:key]];
CGFloat height = 44;
if ([keyString isEqualToString:@"Notes"]) {
if ([keyContents length] > 0) {
CGSize constraint = CGSizeMake(320.0f - (10.0f * 2), 20000.0f);
height = 20 + [keyContents sizeWithFont:[UIFont boldSystemFontOfSize:15] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap].height;
}
}
NSLog(@"Height of %@ with content %@ is %f", keyString, keyContents, height);
if (height <= 44) {
return 44;
}
else {
return height;
}
}
下面是一个太大的条目的截图。
试图放弃显而易见的东西。你的实现是否返回了正确的高度,而UITableView忽略了它?我的意思是,你看到NSLog打印的正确值吗? – 2011-02-06 00:07:13