我有一个UICollectionViewFlowLayout
具有一些可重用性的 collectionView:
- (CategoryCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CategoryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CategoryCell" forIndexPath:indexPath];
[cell.actIn startAnimating];
cell.cellElementRepresentation = [self.localCategoriesObjects objectAtIndex:indexPath.row];
[cell tryToShow]; //this is a important method to my problem
return cell;
}
我评论了你的tryToShow
方法。因为我认为这是一个问题。当我滚动到列表中不可见的元素时,我可以先看到“旧”元素,然后是新元素。这是为什么?我的tryToShow
方法基本上是下载管理器。我试着在评论中描述它。这是代码:
-(void)tryToShow {
NSString* imageFile = self.linkToImageFileSavedOnDisk //This is my local file saved in documentsDirectory.
if([[NSFileManager defaultManager] fileExistsAtPath:imageFile]) {
[self.overlayButton setBackgroundImage:[UIImage imageWithContentsOfFile:imageFile] forState:UIControlStateNormal];
[self disableActIn]; //Here i stop and remove activity indicator.
} else {
// Here i fire NSURLConnection and try to download. When NSURLConnection finished i put image to overlayButton.
}
}
这是委托方法:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
//Here do some stuff to convert Data into UIImage... not important.
[self.overlayButton setBackgroundImage:object forState:UIControlStateNormal];
}
overlayButton 是UICollectionViewCell
. 我有一个自定义类。
我想不通。滚动后如何从indexPath.row
(例如1)图像可见?新的成功下载后,图像立即被新的替换,但这为时已晚。