나는 Grand Central Dispatch을 사용하여 UITableViewCell
의 이미지를 비동기 적으로로드합니다. 이것은 셀이 재사용되고 이전 블록이 잘못된 이미지를로드하는 경우를 제외하고는 잘 작동합니다.GCD로 UITableViewCell 재사용
나의 현재 코드는 다음과 같습니다
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSString *imagePath = [self imagePathForIndexPath:indexPath];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
dispatch_sync(dispatch_get_main_queue(), ^{
cell.imageView.image = image;
[cell setNeedsLayout];
});
});
return cell;
}
지금까지 내가 GCD 큐는 중지 할 수 없습니다 알고있다. 이 국경 사건은 어떻게 방지 될 수 있습니까? 또는이 문제를 해결하기 위해 GCD 대신 다른 것을 사용해야합니까?
GMGridView를 사용하여 엄청난 양의 이미지 축소판을 표시하고 정확하게 동일한 문제가 발생합니다. 또한 GCD를 사용하여 웹 서버의 미리보기 이미지를 즉시로드합니다. – Humayun