2011-07-22 9 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"]; 
関連する問題