【发布时间】:2014-02-19 15:25:57
【问题描述】:
在下面的代码中,我从文本文件下载图像 URL,将其存储在 NSMutableArray 中,然后从 CellforItemAtIndexPath 中的这些 URL 下载图像。但是,当我上下滚动片刻时,错误的图像出现在错误的位置。一秒钟后它会更正,但我想摆脱那个滚动问题。代码如下:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell2";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
AsyncImageView *recipeImageView = (AsyncImageView *)[cell viewWithTag:100];
UILabel *titleView = (UILabel *)[cell viewWithTag:101];
titleView.numberOfLines = 3;
UIImageView *overlay = (UIImageView *)[cell viewWithTag:111];
FXBlurView *blurView = (FXBlurView *)[cell viewWithTag:110];
blurView.tintColor = [UIColor colorWithRed:51.0 green:51.0 blue:51.0 alpha:1];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
hi = [self videoTitle];
images = [self firstPhoto];
// switch to a background thread and perform your expensive operation
// switch back to the main thread to update your UI
dispatch_async(dispatch_get_main_queue(), ^{
NSString *imgSrc;
NSString *url = images[indexPath.row];
imgSrc = url;
if (imgSrc != nil && [imgSrc length] != 0 ) {
[recipeImageView setImageWithURL:[NSURL URLWithString:images[indexPath.row]] placeholderImage:[UIImage imageNamed:@"red.png"]];
}
else {
NSLog(@"noimage");
recipeImageView.image = [UIImage imageNamed:@"red.png"];
}
titleView.text = hi[indexPath.row];
});
});
return cell;
// recipeImageView.image = [UIImage imageNamed:[videoList objectAtIndex:indexPath.row]];
}
有什么想法吗?谢谢。
【问题讨论】:
标签: ios uicollectionview afnetworking