我想根據文本長度調整我在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