Layout 为什么在集合视图中将headerReferenceSize与自调整大小的单元格一起使用会在iOS 8中导致崩溃?

Layout 为什么在集合视图中将headerReferenceSize与自调整大小的单元格一起使用会在iOS 8中导致崩溃?,layout,uicollectionview,ios8,xcode6-beta5,Layout,Uicollectionview,Ios8,Xcode6 Beta5,我设法弄明白了 我想把它作为附件视图的一部分 我撞车了。。。stacktrace的有趣部分如下所示: ** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: ( 0 CoreFoundation

我设法弄明白了

我想把它作为附件视图的一部分

我撞车了。。。stacktrace的有趣部分如下所示:

** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
  0   CoreFoundation    __exceptionPreprocess + 165
  1   libobjc.A.dylib   objc_exception_throw + 45
  2   CoreFoundation    -[__NSArrayM insertObject:atIndex:] + 954
  3   UIKit             -[UICollectionViewFlowLayout layoutAttributesForElementsInRect:] + 384
  4   UIKit             __45-[UICollectionViewData validateLayoutInRect:]_block_invoke + 144
  5   UIKit             -[UICollectionViewData validateLayoutInRect:] + 1396
  6   UIKit             -[UICollectionView layoutSubviews] + 170
  7   UIKit             -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
  8   QuartzCore        -[CALayer layoutSublayers] + 150
  9   QuartzCore        _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
  10  UIKit             -[UIView(Hierarchy) layoutBelowIfNeeded] + 611
  11  UIKit             -[UIInputSetHostView layoutIfNeeded] + 105
  12  UIKit             __43-[UIInputWindowController setInputViewSet:]_block_invoke + 112
  13  UIKit             +[UIView(Animation) performWithoutAnimation:] + 65
  14  UIKit             -[UIInputWindowController setInputViewSet:] + 291
  15  UIKit             -[UIInputWindowController performOperations:withAnimationStyle:] + 50
  16  UIKit             -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1054
  17  UIKit             -[UIResponder becomeFirstResponder] + 468
  18  UIKit             -[UIView(Hierarchy) becomeFirstResponder] + 99
  19  UIKit             -[UITextView becomeFirstResponder] + 75
  ...

这看起来像个苹果虫。为什么布局似乎返回空布局属性?

到目前为止,我的最佳想法是基于此存储库:

在ViewController.swift的第50行,我们有
label.preferredMaxLayoutWidth=320
,它生成一个单元格,填充整个屏幕,如果有足够的文本,则包装行。这将需要改变,以适应任何大小的屏幕您正在使用。然后在每个部分之后,您需要添加足够的文本来填充该标签,就像在第20行中所做的那样
let items=smallitems.componentsSeparatedByString(“”+[onelongitem]


这种方法的问题在于,除了文本之外,我还不知道如何在单元格中放入不同的视图。不过,这对于您的情况可能已经足够了。

如果我设置了一个具有固定项目大小的标题,它就可以正常工作。如果改用estimatedItemSize,则会发生此错误。我的结论是,
estimatedItemSize
有效,但不适用于
headerReferenceSize
您为此申请过雷达吗?有人找到过解决办法吗?目前,我无法使用具有自调整大小布局的标题@fatuhoko,当你说“如果我用某个固定的项目大小设置一个标题,它工作得很好”-你是怎么做到的?我的意思是,如果你忘记了使用
estimatedItemSize
来完全自调整单元格大小,而只是通过设置
itemSize
属性来调整单元格大小,那么你的标题就工作了。i、 e.使用属性或重写
itemSizeForIndexPath
或其他任何内容的旧功能仍然有效。有人找到了解决方法吗?