iOS 15 UICollectionView issue for UICollectionViewRecursion



在Xcode 12和iOS 14之前,应用程序都可以正常工作,但当我升级到Xcode 13/iOS 15时,我的应用程序就停止了工作,出现了以下错误日志

2021-11-26 12:49:38.844428+0530 Mitaja[6170:102791] [UICollectionViewRecursion] cv == 0x7feb458e0000 Enabling recursion trigger logging
2021-11-26 12:49:39.040798+0530 Mitaja[6170:102791] [UICollectionViewRecursion] UICollectionView 0x7feb458e0000 Visible cells update scheduled with call stack:
(
0   UIKitCore                           0x00007fff24644a06 -[UICollectionView _setNeedsVisibleCellsUpdate:withLayoutAttributes:] + 107
1   UIKitCore                           0x00007fff24675708 -[UICollectionView _invalidateLayoutWithContext:] + 1310
2   UIKitCore                           0x00007fff246a660c -[UICollectionViewLayout invalidateLayoutWithContext:] + 200
3   UIKitCore                           0x00007fff2469a329 -[UICollectionViewFlowLayout invalidateLayoutWithContext:] + 667
4   UIKitCore                           0x00007fff246a3b5f -[UICollectionViewFlowLayout _didPerformUpdateVisibleCellsPassWithLayoutOffset:] + 430
5   UIKitCore                           0x00007fff24653a33 -[UICollectionView _updateVisibleCellsNow:] + 10438
6   UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
7   UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
8   UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
9   UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
10  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
11  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
12  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
13  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
14  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
15  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
16  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
17  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
18  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
19  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
20  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
21  UIKitCore                           0x00007fff24653af8 -[UICollectionView _updateVisibleCellsNow:] + 10635
22  UIKitCore                           0x00007fff24657447 -[UICollectionView layoutSubviews] + 325
23  UIKitCore                           0x00007fff255bcaad -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2962
24  QuartzCore                          0x00007fff2893c2b6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 548
25  QuartzCore                          0x00007fff289474f1 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 65
26  QuartzCore                          0x00007fff288830ca _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 652
27  QuartzCore                          0x00007fff288bac47 _ZN2CA11Transaction6commitEv + 699
28  QuartzCore                          0x00007fff288bbfc8 _ZN2CA11Transaction25flush_as_runloop_observerEb + 60
29  CoreFoundation                      0x00007fff20368c77 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
30  CoreFoundation                      0x00007fff2036349c __CFRunLoopDoObservers + 541
31  CoreFoundation                      0x00007fff20363a4c __CFRunLoopRun + 1126
32  CoreFoundation                      0x00007fff20363103 CFRunLoopRunSpecific + 567
33  GraphicsServices                    0x00007fff2c851cd3 GSEventRunModal + 139
34  UIKitCore                           0x00007fff24ffbe63 -[UIApplication _run] + 928
35  UIKitCore                           0x00007fff25000a53 UIApplicationMain + 101
36  Mitaja                              0x0000000108209adf main + 63
37  dyld                                0x000000010ca84e1e start_sim + 10
38  ???                                 0x000000010f5854fe 0x0 + 4552414462
39  ???                                 0x0000000000000000 0x0 + 0
40  Mitaja                              0x0000000106ff7000 __dso_handle + 0
)

2021-11-26 12:49:40.736245+0530 Mitaja[6170:102791] [UICollectionViewRecursion] <UICollectionView: 0x7feb458e0000; frame = (122.5 0; 291.5 0); clipsToBounds = YES; hidden = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x600002764810>; layer = <CALayer: 0x600002d43b00>; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 0, 0}; layout: <UICollectionViewFlowLayout: 0x7feb43fa4810>; dataSource: <Mitaja.JPostCardVC: 0x7feb452ed000>> is stuck in its update/layout loop. See previous logs in the "UICollectionViewRecursionCategory" to find callers that scheduled a recursive update
2021-11-26 12:49:40.736365+0530 Mitaja[6170:102791] *** Assertion failure in -[UICollectionView _setNeedsVisibleCellsUpdate:withLayoutAttributes:], UICollectionView.m:1511

解决方案应该是什么?
任何帮助都将不胜感激
我试过很多次调试,但都没有成功,请帮我。

编辑

"UICollectionView(<UICollectionView 0x7fd6ca190000>(在其更新/布局循环中卡住。发生这种情况的原因有很多,包括自调整视图的首选属性没有返回一致的大小。要调试此问题,请检查控制台应用程序中的";UICollectionViewRecursion";类别">

崩溃的错误描述

我在iOS 15中遇到了类似的问题。在我的案例中,它是通过重写UICollectionViewFlowLayout方法修复的:

override func shouldInvalidateLayout(forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes, 
withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes) -> Bool {
return true
}

我们在使用Xamarin.Forms的iOS应用程序中遇到了同样的错误。我们通过在集合视图中显式指定项目的高度来解决问题。不是一个永久的解决方案,但应该能够让你度过崩溃。

我在这里https://github.com/WenchaoD/FSCalendar/issues/1351在上回答了类似的问题;初步判断是,在计算布局中的项目大小时,项目的总宽度超过了屏幕宽度。建议在计算物品尺寸时使用地板向下取整,暂时解决这一问题;相同的代码是在ios15版本2中可以正常运行之前;此外,很奇怪的是,我在iPhone 11上没有问题,而且闪回会出现在iPhone 11 Pro max 上

https://github.com/xamarin/Xamarin.Forms/issues/15230提到了几个变通办法。我知道是Xamarin.Forms,但在引擎盖下ItemSizingStrategy=";MeasureFirstItem";可能转换为UICollectionView 上的iOS属性

我遇到过这个问题,它已经解决了。

在我的案例中,根本原因是UICollectionViewFlowLayout子类中的覆盖方法有一个糟糕的实现,它们保留了所有集合大小(缓存它们(以供以后重用,而不是在委托调用时计算。

因此,您应该检查从UICollectionViewFlowLayout继承的类,以确保它们没有引用循环,也没有递归,并确保其安全。

希望你有一个好的解决方案。

有两件简单的事情可以避免这种崩溃。

  1. 在单元格内,覆盖函数preferredLayoutAttributesFitting,并在对x、y、高度和宽度进行四舍五入后返回layoutAttribute
  2. 正在删除我们为默认或估计的宽度和高度设置的estimatedItemSize

最新更新