我想根据文本长度调整我在UITableView中的行高度。我有以下代码:在UITableView中格式化动态行高度挣扎
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellText =[[topics objectAtIndex:indexPath.row] name];
UIFont *cellFont = [UIFont fontWithName:@"ArialMT" size:17.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height + 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"ArialMT" size:17.0];
}
}
然而,随着的UIImageView和UIDetailText弄乱了,如下图所示的图像:
我该如何解决这个问题?
我已经试过:
[cell.imageView setContentMode:UIViewContentModeScaleToFill];
[cell.imageView setFrame:CGRectMake(0, 0, 16,16)];
[cell.imageView setBounds:CGRectMake(0, 0, 16,16)];
[cell.imageView setAutoresizingMask:UIViewAutoresizingNone];
[cell.imageView setAutoresizesSubviews:NO];
,并没有一个似乎工作
你在哪里设置图像? – 2011-05-07 17:26:50
via cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:URL]]]];我没有在代码中显示 – adit 2011-05-07 17:36:39
您是否改变了imageView的contentMode? – 2011-05-07 17:38:53