imageNamedではなくimageWithContentsOfFileを使用すると、UITableViewのスクロールでパフォーマンスの問題が発生します。私のコードを以下に示します。iPhone:imageWithContentsOfFileのUITableViewパフォーマンスの問題
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UniversalAppAppDelegate *delegate = (UniversalAppAppDelegate *) [[UIApplication sharedApplication] delegate];
NSDictionary *res = [[delegate comments] objectAtIndex:indexPath.section];
if (cell == nil)
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
......
// This line has a problem...when I use imageNamed here instead of imageWithContentsOfFile, it works absolutely fine
imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imagepath]];
[imageView setFrame: CGRectMake(30, 10, 55, 55)];
[sectionHeaderView addSubview:imageView];
......
cell.backgroundView = sectionHeaderView;
return cell;
私もcaching画像が、それでも同じ問題を試してみました。 imageNamedのみが正常に動作しますが、ドキュメントフォルダに格納されたイメージのパスを指定して動的に変更する必要があるため、使用できません。誰も私にこの問題を解決する方法を教えてもらえますか?
キャッシュコード:
NSMutableDictionary *thumbnailCache = [[NSMutableDictionary alloc] init];
- (UIImage*)thumbnailImage:(NSString*)fileName
{
UIImage *thumbnail = [thumbnailCache objectForKey:fileName];
if (nil == thumbnail)
{
NSString *thumbnailFile = [self filePath:fileName];
thumbnail = [UIImage imageWithContentsOfFile:thumbnailFile];
[thumbnailCache setObject:thumbnail forKey:fileName];
}
return thumbnail;
}
使用法:
imageView = [[UIImageView alloc] initWithImage:[delegate thumbnailImage:[res objectForKey:@"ImageName"]]];
これは私がキャッシングすることを意味しています。私はすでにそれをやっているが、それはどちらも役に立たなかった。私のキャッシュコードを追加しました。 – applefreak
ありがとうございました。キャッシュを使用しているときに 'cellForRowAtIndexPath'の内部で何を変更しましたか? – Mutix
私の悪い!私はこの辞書を初期化するのを忘れていました。初期化され、その後正常に動作しました! – applefreak