首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionView sizeForItemAt IndexPath

UICollectionView sizeForItemAt IndexPath
EN

Stack Overflow用户
提问于 2017-05-13 15:58:47
回答 1查看 1.8K关注 0票数 1

我试图为我的手机设定大小,根据里面的内容,这是我的代码,它崩溃了,我找不到错误的介面。

代码语言:javascript
复制
extension TimelineCollectionVC: UICollectionViewDelegateFlowLayout {



func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "timeline", for: indexPath) as? Timeline

    cell?.textView.translatesAutoresizingMaskIntoConstraints = true
    cell?.textView.sizeToFit()



    if cell?.containerView.subviews.count == 0 {
        cell?.containerHeight.constant = 1
    } else {
        cell?.containerHeight.constant = (cell?.containerView.subviews.first?.frame.size.height) ?? 80
    }

    let cellHeight = (cell?.upperView.bounds.height)! + (cell?.textView.bounds.height)! + (cell?.containerView.bounds.height)! + (cell?.lowerView.bounds.height)!


    return CGSize(width: 375, height: cellHeight)



}

}

原因:‘-*NSCFString setSizeHasBeenSet::未识别的选择器发送到实例0x610000076bc0’*第一次抛出调用堆栈:(0 CoreFoundation 0x0000000109dd9d4b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x00000001094d921e objc_exception_throw + 48 2 CoreFoundation 0x0000000109e49f04 -NSObject(NSObject) doesNotRecognizeSelector:+ 132 3 CoreFoundation 0x00000109d5f005 __ __)_forwarding_ + 1013 4 CoreFoundation 0x0000000109d5eb88 _CF_forwarding_prep_0 + 120 5 UIKit 0x00000001080d9485 -UICollectionViewFlowLayout _getSizingInfosWithExistingSizingDictionary:+ 3691 6 UIKit 0x00000001080da97b -UICollectionViewFlowLayout _fetchItemsInfoForRect:+ 127 7 UIKit 0x00000001080d3504 -UICollectionViewFlowLayout prepareLayout + 273 8UIKit 0x00000001080f3d6c -UICollectionViewData _prepareToLoadData + 159 9 UIKit 0x00000001080f4618 -UICollectionViewData validateLayoutInRect:+ 57 10 UIKit 0x000000010809b6d4 -UICollectionView layoutSubviews + 232 11 UIKit 0x000000107817ab8 -UIView(CALayerDelegate) layoutSublayersOfLayer:+ 1237 12 QuartzCore_ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 14 QuartzCore 0x00000106fc12be _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 15 QuartzCore 0x0000000106f4f318 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280 16 QuartzCore 0x0000000106f7c3ff _ZN2CA11Transaction6commitEv + 475 17 QuartzCore0x00000106f7cd6f _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113 18 CoreFoundation 0x0000000109d7e267 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION** + 23 19 CoreFoundation 0x0000000109d7e1d7 __CFRunLoopDoObservers + 391 20 CoreFoundation 0x0000000109d628a6 CFRunLoopRunSpecific + 454 21 UIKit 0x000000010774 _run _run+ 43422 UIKit 0x0000000107752c68 UIApplicationMain + 159 23 Moden 0x0000000104ab4fbf main + 111 24 libdyld.dylib 0x000000010ad4e68d start +1) libc++abi.dylib:以NSException (lldb)类型的未加例外终止

EN

回答 1

Stack Overflow用户

发布于 2017-05-13 16:14:35

您不应该在这里使用dequeueReusableCell。这只是为了创建新的单元格。在本例中,您希望获得一个现有的单元格,并且可能在UICollectionView类中使用UICollectionView

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43955143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档