【问题标题】:Creating a thumbnail for UITableViewCell imageView为 UITableViewCell imageView 创建缩略图
【发布时间】:2011-07-22 16:06:56
【问题描述】:

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

- (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;

}

【问题讨论】:

    标签: iphone uitableview


    【解决方案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"];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      • 2011-02-18
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      • 2012-03-19
      • 2012-02-04
      相关资源
      最近更新 更多