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