【发布时间】:2015-02-06 05:03:04
【问题描述】:
大家好,我正在显示来自网络服务的图像,现在我的问题是我遇到了一些不知道的奇怪问题
这是我的代码 sn-p
- (CustomCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CustomCell *cell = (CustomCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"CustomCell" forIndexPath:indexPath];
NSString *strurl=[[arrUrlImage objectAtIndex:indexPath.row] objectAtIndex:0];
NSURL *url = [NSURL URLWithString:strurl];
ImageRequest *request = [[ImageRequest alloc] initWithURL:url];
cell.imageView.image=[UIImage imageNamed:@"purple.jpg"];
UIImage *image = [request cachedResult];
if (image) {
cell.imageView.image=image;
} else {
[request startWithCompletion:^(UIImage *image, NSError *error) {
if (image && [[collectionView indexPathsForVisibleItems] containsObject:indexPath]) {
@try
{
[_collectionView performBatchUpdates:^{
[_collectionView reloadItemsAtIndexPaths:@[indexPath]];
} completion:nil];
}
@catch (NSException *except)
{
NSLog(@"%@", except.description);
}
}
}];
}
if (indexPath.row==arrUrlImage.count-1) {
NSLog(@"load more image.");
NSString *nextPageUrl=[[arrMedia valueForKey:@"pagination"] valueForKey:@"next_url"];
[arrMedia removeAllObjects];
NSLog(@"%@",nextPageUrl);
ShowNetworkActivityIndicator();
[self grabMedia:nextPageUrl];
}
return cell;
}
我收到此错误消息的异常
Assertion failure in -[UICollectionView _endItemAnimations], /SourceCache/UIKit_Sim/UIKit-2903.23/UICollectionView.m:3716
和异常日志:无效更新:第0节中的项目数无效。更新后现有节中包含的项目数(80)必须等于更新前该节中包含的项目数( 60),加上或减去从该部分插入或删除的项目数(1 个插入,1 个删除),加上或减去移入或移出该部分的项目数(0 移入,0 移出)。
任何帮助。
【问题讨论】:
-
只需尝试在
_collectionView上注释您执行批量更新的行
标签: ios xcode uikit uicollectionview