사용자 정의 UICollectionViewCell
인 UICollectionView
구현이 있습니다. 데이터 배열이 인터넷에서 가져 오지만 사용자가 콘텐츠에 액세스 할 때 이미지가 다운로드됩니다.UICollectionView에서 GCD 및 셀 재사용
이것은 아마도 가장 효율적인 방법은 아니지만 이런 식으로 남겨 둘 계획은 아니지만 문제 해결에 어려움을 겪었습니다. 세포가 "캐시 된"또는 "오래된"이미지를 표시하고 있으며 천천히 컬렉션보기를 스크롤하면 셀 이미지가 계속 변경됩니다.
이것은 실제 셀 이미지가 그 순간 그 순간에 사용할 수없는 문제 일 수 있으며 내 질문은 어떻게 빈 셀 또는 일부 활성 활성 모니터를 강제로 표시하고 잘못된 이미지를 표시하지 않는 것입니까? 사전에
감사합니다, 피니언
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @"Event";
EventCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *title = [[events objectAtIndex:indexPath.item] objectForKey:@"title"];
NSString *imageUrl = [[[events objectAtIndex:indexPath.item] objectForKey:@"photo"] objectForKey:@"url"];
dispatch_queue_t imageFetchQ = dispatch_queue_create("image fetched", NULL);
dispatch_async(imageFetchQ, ^{
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];
if (imageData)
{
dispatch_async(dispatch_get_main_queue(), ^{
cell.eventImage.image = [UIImage imageWithData:imageData];
cell.eventTitle.text = title;
});
}
});
return cell;
}
대신이 튜토리얼에서와 같이 NSOperationQueue를 사용하는 것이 좋습니다. http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues –
자습서를 따르려고했으나 재사용 문제는 실제로 다루지 않습니다. NSOperationQueue가 그런 솔루션에 들어갈 수있는 곳을 보았지만 문제는 그대로 남아 있습니다.어떤 이미지가 셀당 표시되는지 확인하는 메커니즘의 일부 유형을 구현해야한다고 생각합니다. 방법 그러나 확실하지 않은. 아직. – Pinion