2011-07-22 33 views
0

我正在寻找如何调整UITableViewCells的图像大小,使它们大小相同。我遇到了这个帖子UITableViewCell's imageView fit to 40x40,并添加了创建缩略图的方法作为类别。它可以工作,但现在看起来比较慢,而且我想知道我是否将某些东西遗留下来或错误地使用该类别。目前,在我的cellForRowAtIndexPath方法中,这是我创建一个新的图像,并使用此类别来调整它的大小。所以我猜这不是做这件事的方法,因为现在它每次都要在表格中显示时进行绘制?我是否需要为每行创建缩略图数组并使用它来代替原始图像?如果是这样,我将如何跟踪这两个数组(一个用于文本,一个用于图像),以防重新排序。谢谢!为UITableViewCell创建缩略图imageView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *PopoverIdentifier = @"PopoverIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PopoverIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PopoverIdentifier] autorelease]; 
    } 
    NSUInteger row = [indexPath row]; 
    GTest *gt = [_gtList objectAtIndex:row]; 
    cell.textLabel.text = gt.Name; 
    UIImage *cellImage = [UIImage imageNamed:gt.ImageFile]; 
    cellImage = [UIImage scale:cellImage toSize:CGSizeMake(50, 50)]; 
    cell.imageView.image = cellImage; 
    return cell; 

} 

回答

1

,你可以创造出保存图像和文本数据字典对象的数组:

NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:text,@"text",image,@"image"nil]; 
[array addObject:dict]; 

,并在你的cellForRowAtIndexPath:

NSDictionary* dict = [array objectAtIndex:i]; 
UIImage* img = [dict objectForKey:@"image"]; 
NSString* txt = [dict objectForKey:@"text"];