【发布时间】:2015-12-20 08:52:07
【问题描述】:
说明:-
您好,当我们运行此代码时,单元格重定位图像在滚动时发生变化。
请告诉我如何解决。
- (UICollectionViewCell )collectionView:(UICollectionView )collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cellidentifier";
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
NSString * string = [_temp objectAtIndex:indexPath.row];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// retrive image on global queue
UIImage * img = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:string]]];
dispatch_async(dispatch_get_main_queue(), ^{
cell.imageView.image = img;
});
});
return cell;
}
【问题讨论】:
-
最好将数据加载到您的 model 而不是 view 中,并且当 model 是准备好你可以从你的 model 填充 view - 通常这是标准方式。
标签: objective-c uitableview lazy-loading objective-c-blocks