简体   繁体   English

UICollectionView和iOS 7导致SVPullToRefresh崩溃

[英]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.

相关问题 iOS 7中的UICollectionView奇怪崩溃 - UICollectionView strange crash in iOS 7 当内容高度小于高度时,SVPullToRefresh无法与UICollectionView一起使用 - SVPullToRefresh not working with UICollectionView when content height is less than the height 当标题在屏幕上时,IOS UICollectionView insertItemsAtIndexPaths崩溃 - IOS UICollectionView insertItemsAtIndexPaths crash when header is on screen iOS SVPullToRefresh同时“加载更多”和“刷新” - iOS SVPullToRefresh “Load more” and “Refresh” at the same time UICollectionView崩溃? - UICollectionView Crash? UICollectionView崩溃 - Crash on UICollectionView iOS9中的[_UIFlowLayoutSection updateEstimatedSizeForSection]中的UICollectionView崩溃 - Xcode7 - UICollectionView crash in [_UIFlowLayoutSection updateEstimatedSizeForSection] in iOS9 - Xcode7 UICollectionView-iOS 10-在iPhone 6 Plus模拟器上崩溃但可在真实设备上运行 - UICollectionView - iOS 10 - crash on iPhone 6 Plus simulator but works on real device 为什么将 UICollectionView 上的单元格出列会导致应用程序在 iOS 13 上崩溃? - Why dequeuing a cell on UICollectionView causes the app to crash on iOS 13? UICollectionView 在 iOS 16 beta 上移动项目时崩溃 - UICollectionView crash when moving items on iOS 16 beta
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM