Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift UICollectionView SizeForestMat IndexPath_Swift_Uicollectionview_Size_Cell - Fatal编程技术网

Swift UICollectionView SizeForestMat IndexPath

Swift UICollectionView SizeForestMat IndexPath,swift,uicollectionview,size,cell,Swift,Uicollectionview,Size,Cell,我正试着根据里面的东西来设置我手机的大小 这是我的代码,它崩溃了,我找不到错误消息 extension TimelineCollectionVC: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: In

我正试着根据里面的东西来设置我手机的大小 这是我的代码,它崩溃了,我找不到错误消息

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:::::]:无法识别的选择器已发送到实例0x61000076BC0' ***第一次抛出调用堆栈: ( 0 CoreFoundation 0x0000000109dd9d4b例外预处理+171 1 libobjc.A.dylib 0x00000001094d921e objc_异常_抛出+48 2 CoreFoundation 0x0000000109e49f04-[NSObject(NSObject)不识别选择器:][132 3 CoreFoundation 0x0000000109d5f005_uuuuuuuuuuu转发+1013 4 CoreFoundation 0x0000000109d5eb88\u CF\u转发\u准备\u 0+120 5 UIKit 0x00000001080d9485-[UICollectionViewFlowLayout\u获取现有尺寸字典的尺寸:][3691 6 UIKit 0x00000001080da97b-[UICollectionViewFlowLayout\u fetchItemsInfoForRect:+127 7 UIKit 0x00000001080d3504-[UICollectionViewFlowLayout准备]+273 8 UIKit 0x00000001080f3d6c-[UICollectionViewData\u prepareToLoadData]+159 9 UIKit 0x00000001080f4618-[UICollectionViewData validateLayoutInRect:+57 10 UIKit 0x000000010809b6d4-[UICollectionView布局子视图]+232 11 UIKit 0x0000000107817ab8-[UIView(CALayerDelegate)布局层的子层:+1237 12夸脱核心0x0000000106fcdbf8-[CALayer layoutSublayers]+146 13夸脱核心0x0000000106fc1440,如果需要,可分层布局交易+366 14 QuartzCore 0x0000000106fc12be\u ZN2CA58层布局\u和\u显示\u如果需要的话\u交易+24 15 QuartzCore 0x0000000106f4f318_ZN2CA7Context18commit_TransactionPNS_11 Transactione+280 16夸脱矿0x0000000106f7c3ff_ZN2CA11交易承诺+475 17 QuartzCore 0x0000000106f7cd6f_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv+113 18 CoreFoundation 0x0000000109d7e267CFRUNLOOP\u正在调用一个观察者回调函数 19 CoreFoundation 0x0000000109d7e1d7\uu cfrunloopdoobserver+391 20 CoreFoundation 0x0000000109d628a6 CFRunLoopRunSpecific+454 21 UIKit 0x000000010774caea-[UIApplication_run]+434 22 UIKit 0x0000000107752c68 UIApplicationMain+159 23模式0x0000000104ab4fbf主+111 24 libdyld.dylib 0x000000010ad4e68d启动+1 ) libc++abi.dylib:以NSException类型的未捕获异常终止
(lldb)

您不应该在此处使用
dequeueReusableCell
。这仅用于创建新单元。在这种情况下,您希望获得一个现有的单元格,并且可能应该在
UICollectionView
类中使用
func cellForItem(在indexPath:indexPath)->UICollectionViewCell?

是否可以发布崩溃日志,或者至少是崩溃日志的顶部?使用调试器并逐步完成代码。顺便说一句-没有理由将
单元格
设置为可选。如果它实际上不是一个
时间线
实例,那么您希望它崩溃,因为这在您的应用程序中是一个明显的错误。然后,您可以在所有的
单元格
引用中删除所有不必要的
。然后你就可以摆脱那些讨厌的
运算符(意思是“此处崩溃”)@Scotthompson我没有崩溃日志,它只是崩溃并显示我的AppDelegate类(Thread1:EXC_BAD_ACCESS~)@rmaddy删除的标记仍然崩溃如果我返回CGSize(宽度:375,高度:600),但上面没有任何东西,它工作正常。但一旦涉及到手机,就会发生崩溃,而且没有理由显示我有类似的问题,但只有当我在手机上使用属性文本时才会发生。您应该使用let sizingView=Bundle.main.loadNibNamed(“MyNib”,所有者:self,选项:nil)?[0]as?MyCelllet sizingView=Bundle.main.loadNibNamed(“MyNib”,所有者:self,选项:nil)?[0]作为?迈塞尔,但这并不能解决这个问题