我用下面的代码大小UITableViewCellStyleSubtitle细胞,使其适用于可以运行一个以上的一行文字:调整大小UITableViewCells中的iOS4对IOS3
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGRect frame = [UIScreen mainScreen].bounds;
CGFloat width = frame.size.width;
int section = indexPath.section;
int row = indexPath.row;
NSString *title_string = [[my_array_ objectAtIndex:row]
valueForKey:@"keyOne"];
NSString *detail_string = [[my_array_ objectAtIndex:row]
valueForKey:@"keyTwo"];
CGSize title_size = {0, 0};
CGSize detail_size = {0, 0};
if (title_string && ![title_string isEqualToString:@""]) {
title_size = [title_string sizeWithFont:
[UIFont systemFontOfSize:TITLE_FONT_SIZE]
constrainedToSize:CGSizeMake(width, 4000)
lineBreakMode:UILineBreakModeWordWrap];
}
if (detail_string && ![detail_string isEqualToString:@""]) {
detail_size = [detail_string sizeWithFont:
[UIFont systemFontOfSize:DETAIL_FONT_SIZE]
constrainedToSize:CGSizeMake(width, 4000)
lineBreakMode:UILineBreakModeWordWrap];
}
CGFloat title_height = title_size.height;
CGFloat detail_height = detail_size.height;
CGFloat content_size = title_height + detail_height;
CGFloat height;
switch (section) {
case 0:
height = content_size; //+ offset;
break;
default:
height = 44.0;
break;
}
return height;
}
这iOS4的运行正常*并给出细胞。适应文本。 (如果它们有点太大但没关系)
但是当我在iOS3中尝试这个时*单元格乱了:textLabel在单元格中出现低位,并且detailLabel文本经常溢出下一个单元格或被截断为“...”。 textLabel似乎出现在单元格的中间,而不是顶部。
iOS3和iOS4可能会导致这种情况有什么不同?我能做些什么来解决这个问题?或者,有没有一种可以替代上述两种iOS应用程序的好方法(比如说)。
感谢您提前。
感谢您的帖子。在这个阶段,它看起来更容易去定制我自己的细胞。 – SK9 2011-02-06 13:16:46