テーブル ビューといくつかのカスタム セルに問題があります。これが私のコードです:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellForRowAtIndexPath");
static NSString *MyIdentifier = @"customCell";
EventTableCell *cell = (EventTableCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
//cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
[[NSBundle mainBundle] loadNibNamed:@"EventTableCell" owner:self options:nil];
cell = self.eventCell;
}
//Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
[[cell eventNameLabel] setText:[[stories objectAtIndex: storyIndex] objectForKey: @"title"]];
[[cell eventDateLabel] setText:[[stories objectAtIndex: storyIndex] objectForKey: @"date"]];
NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
//NSString *string = [[NSString alloc] stringWithString:[[stories objectAtIndex: storyIndex] objectForKey: @"link"]];
NSURL *url = [NSURL URLWithString:storyLink];
NSData *data = [[NSData alloc] initWithContentsOfURL: url];
UIImage *image = [UIImage imageWithData: data];
[[cell eventImage] setImage:image];
return cell;
}
私のテーブルには、これらのカスタム セルが多数あり、ビューが一度に表示できる数を超えています。したがって、すべてのセルを表示するには、上下にスクロールする必要があります。私の問題はこれです。スクロールすると大幅に遅れ、デバッガーコンソールでは、新しいセルが表示されるたびに cellForRowAtIndexPath が呼び出されます。各セルには、URL からダウンロードされた画像が含まれているため、UIImage に変換する必要があります。これが遅れの原因だと思います。
画像をダウンロードし、アプリで大きな遅延を引き起こすことなくセルに表示するために何をする必要があるかについて、誰かが私に指示できますか?
IE: セルを表示する前に画像が画像として保存されるように、ダウンロード/変換コードをどこに配置しますか?
ありがとう、
ジャック