[英]SVPullToRefresh crash with UICollectionView and iOS 7
I have this collection view which I want to add SVPullToRefresh's Infinite Scroll feature. 我有这个集合视图,我想添加SVPullToRefresh的无限滚动功能。
The collection view is set with 1 section and n
(variable) cells. 收集视图设置有1个分区和
n
(变量)单元格。
I included the feature: 我包括了该功能:
__weak MyClass *weakSelf = self;
[_collection addInfiniteScrollingWithActionHandler:^ {
[weakSelf loadNextPage];
}];
And the collection view shows perfectly as it should. 集合视图可以完美显示。 On iOS 6, the method
-loadNextPage
is called normally and the app runs with no problems. 在iOS 6上,通常会调用
-loadNextPage
方法,并且该应用程序可以正常运行。 On the other hand, on iOS 7, when the VC is about to call the method, the app crashes with the following error: 另一方面,在iOS 7上,当VC要调用该方法时,该应用程序崩溃并显示以下错误:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView recieved layout attributes for a cell with an index path that does not exist: <NSIndexPath: 0x1ca8fc50> {length = 2, path = 1 - 0}'
I've been trying to find what exactly is the piece of code, or which part in the code flow the exception appears, but I can't find it. 我一直在尝试查找代码段的确切内容,或者异常出现在代码流的哪一部分,但我找不到。
Edit: added some code: 编辑:添加了一些代码:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ProductCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
Product *product = [_productList objectAtIndex:[indexPath row]];
[cell setName:[product name]];
[cell setImage:[product imageURL]];
[cell setPrice:[product formattedPrice]];
[cell setDistance:[product formattedDistance]];
return cell;
}
Try 尝试
- (NSInteger)numberOfItemsInSection:(NSInteger)section {
[_collection.collectionViewLayout invalidateLayout]
}
What we are doing here is, when we have more data to be rendered, we invalidate the current collection view layout as it will not work with new data and the collection view will layout itself with new available data. 我们在这里所做的是,当我们要渲染更多数据时,我们将使当前的集合视图布局无效,因为它不适用于新数据,并且集合视图将使用新的可用数据进行布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.