简体   繁体   English

UICollectionView-iOS 10-在iPhone 6 Plus模拟器上崩溃但可在真实设备上运行

[英]UICollectionView - iOS 10 - crash on iPhone 6 Plus simulator but works on real device

I've created an UICollectionView that works fine on small devices like iPhone 5s/SE/6/6s/7 on both simulator and real device, but I have a strange situation when it comes about iPhone 6Plus, iPhone 7Plus and any iPad version. 我创建了一个UICollectionView,它可以在模拟器和真实设备上的小型设备(如iPhone 5s / SE / 6 / 6s / 7)上正常运行,但是当涉及到iPhone 6Plus,iPhone 7Plus和任何iPad版本时,我的情况很奇怪。 It works fine on real device, but it crashes in simulator with the following error: 它可以在真实设备上正常运行,但是会在模拟器中崩溃,并显示以下错误:

Assertion failure in -[_UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:invalidationContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.5.2/UIFlowLayoutSupport.m:823 -[_ UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:invalidationContext:],/ BuildRoot / Library / Caches / com.apple.xbs / Sources / UIKit_Sim / UIKit-3600.5.2 / UIFlowLayoutSupport.m:823中的声明失败

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionViewFlowLayout internal error' 由于未捕获的异常“ NSInternalInconsistencyException”而终止应用程序,原因:“ UICollectionViewFlowLayout内部错误”

What I found out so far is that if I remove the estimatedItemSize it works fine but the auto-layout doesn't anymore, but if I have that enabled it crashes in simulator. 到目前为止,我发现的是,如果删除了EstimatedItemSize,它可以正常工作,但是自动布局不再可用,但是如果我启用了它,则它会在模拟器中崩溃。

I am using the latest Xcode version and iOS 10. 我正在使用最新的Xcode版本和iOS 10。

Any ideas why it's crashing? 任何想法为什么它崩溃?

Calling invalidateLayout before layout is a workaround for this issue. 在布局之前调用invalidateLayout是解决此问题的方法。

In a UIViewController subclass: UIViewController子类中:

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    collectionView.collectionViewLayout.invalidateLayout()
}

or in a UIView subclass: 或在UIView子类中:

override func layoutSubviews() {
    super.layoutSubviews()
    collectionView.collectionViewLayout.invalidateLayout()
}

This is some strange bug in iOS10 with iPhone Plus devices only. 仅在使用iPhone Plus设备的iOS10中,这是一个奇怪的错误。 I've faced the same issue, my solution was to call layoutIfNeeded like this: 我遇到了同样的问题,我的解决方案是这样调用layoutIfNeeded:

 func numberOfSections(in collectionView: UICollectionView) -> Int { collectionView.layoutIfNeeded() // Patch: only to solve UIKit crash on Plus models return 1 } 

Doing the same thing in different UICollectionViewDataSources methods will work as well 在不同的UICollectionViewDataSources方法中执行相同的操作也将起作用

Answer that worked for me based on orxelm 's answer on collectionViewContentSize in iOS 10 using self-sizing cells 基于orxelm 在iOS 10中使用自调整大小的单元格collectionViewContentSize的回答为我解决的问题

Invalidating the layout seemed to prevent my collectionView from using my flow layout, and instead used the default layout. 使布局无效似乎阻止了我的collectionView使用我的流程布局,而是使用了默认布局。 This forced all my cells to be the same size which was not the desired outcome (for me anyway). 这迫使我所有细胞的大小都相同,这并不是理想的结果(无论如何对我而言)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序在设备上崩溃但在模拟器 iOS 上工作 - App crash on device but works on simulator iOS iOS应用可在模拟器上运行,但不能在真实设备上运行 - iOS app works on simulator but not on real device Flutter 应用程序在启动时崩溃(仅 IOS,模拟器和真机都有) - Flutter app crash on startup (only IOS, both simulator and real device) iOS App在Simulator上运行正常,但在真实的iOS设备上崩溃 - iOS App works fine with Simulator but Crashes with a real iOS device Xcode 5和iOS 7模拟器/设备崩溃并出现僵尸错误-适用于iOS6 - Xcode 5 and iOS 7 Simulator/Device Crash with zombie error - Works on iOS6 Xamarin.ios 不适用于真正的 iOS 设备,但它适用于模拟器 - Xamarin.ios does NOT work on real iOS device but it works on Simulator Xcode 8.0 GM iPhone Simulator(iOS 10)崩溃 - Crash on Xcode 8.0 GM iPhone Simulator (iOS 10) ios模拟器构建有效,但真实设备构建失败 - ios simulator build works but real device build fails in flutter Firebase 在 ios 模拟器上运行良好,但在真实设备上不起作用 - Firebase works fine on ios simulator but it does't work on real device 适用于iOS模拟器,但不适用于iPhone - Works on iOS Simulator but not on iPhone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM