UICollectionView - iOS 10 - 在iPhone 6 Plus模拟器上崩溃但在真实设备上运行 [英] UICollectionView - iOS 10 - crash on iPhone 6 Plus simulator but works on real device

查看:827
本文介绍了UICollectionView - iOS 10 - 在iPhone 6 Plus模拟器上崩溃但在真实设备上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个UICollectionView,可以在模拟器和真实设备上的iPhone 5s / SE / 6 / 6s / 7等小型设备上正常工作,但是当我遇到iPhone 6Plus,iPhone 7Plus和任何其他产品时,我都有一个奇怪的情况。 iPad版。它在真实设备上工作正常,但它在模拟器中崩溃并出现以下错误:

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. It works fine on real device, but it crashes in simulator with the following error:


断言失败 - [_ UIFlowLayoutSection
computeLayoutInRect :forSection:invalidating:invalidationContext:],
/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.5.2/UIFlowLayoutSupport.m:823

Assertion failure in -[_UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:invalidationContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.5.2/UIFlowLayoutSupport.m:823

由于未捕获的异常而终止应用
'NSInternalInconsistencyException',原因:
'UICollectionViewFlowLayout内部错误'

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionViewFlowLayout internal error'

到目前为止我发现的是,如果我删除了estimatedItemSize,它工作正常,但自动布局不再存在,但是如果我启用它会在模拟器中崩溃。

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.

我使用的是最新的Xcode版本和iOS 10.

I am using the latest Xcode version and iOS 10.

任何想法为什么会崩溃?

Any ideas why it's crashing?

推荐答案

在布局是此问题的解决方法之前,调用 invalidateLayout

Calling invalidateLayout before layout is a workaround for this issue.

在a UIViewController 子类:

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

或在 UIView 子类中:

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

这篇关于UICollectionView - iOS 10 - 在iPhone 6 Plus模拟器上崩溃但在真实设备上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆