ios – 使用带有FlowLayout的UICollectionView的单元格滚动UITableView时,应用程序崩溃

ios – 使用带有FlowLayout的UICollectionView的单元格滚动UITableView时,应用程序崩溃,第1张

概述该应用程序使用 Xcode 7.3.1在 Swift 2.2中编写. 我有一个UITableView,其单元格具有UICollectionView和水平FlowLayout.当我快速上下滚动桌面视图并且不让它停在设备(iPad Air 2,iOS 9.3.2)或模拟器上时,应用程序崩溃了 EXC_BAD_ACCESS 在AppDelegate中. 该应用程序没有在视图控制器中为didReceive 该应用程序使用 Xcode 7.3.1在 Swift 2.2中编写.

我有一个UItableVIEw,其单元格具有UICollectionVIEw和水平FlowLayout.当我快速上下滚动桌面视图并且不让它停在设备(iPad Air 2,iOS 9.3.2)或模拟器上时,应用程序崩溃了

EXC_BAD_ACCESS

在AppDelegate中.

该应用程序没有在视图控制器中为dIDReceiveMemoryWarning()设置断点.

似乎代码崩溃了

[UICollectionVIEwData invalIDateItemsAtIndexPaths:]

要么

[_UIFlowLayoutSection computeLayoutInRect:forSection:invalIDating:]

其次是

0_dispatch_barrIEr_async_f_slow.

堆栈跟踪不会指向任何应用程序代码行.

模拟器的控制台堆栈跟踪(在设备上崩溃时没有控制台堆栈跟踪):

*** Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: '+[_UIFlowLayoutItem frame]: unrecognized selector sent to class 0x110f9ecc0'*** First throw call stack:(0   CoreFoundation                      0x000000011259cd85 __exceptionPreprocess + 1651   libobjc.A.dylib                     0x00000001137d3deb objc_exception_throw + 482   CoreFoundation                      0x00000001125a5c3d +[NSObject(NSObject) doesNotRecognizeSelector:] + 2053   CoreFoundation                      0x00000001124ebcfa ___forwarding___ + 9704   CoreFoundation                      0x000000011259e1f8 __forwarding_prep_1___ + 1205   UIKit                               0x0000000110b1d8b5 -[UICollectionVIEwData invalIDateItemsAtIndexPaths:] + 2736   UIKit                               0x0000000110ae26b7 -[UICollectionVIEw _invalIDateWithBlock:] + 627   UIKit                               0x0000000110ae2a6f -[UICollectionVIEw _invalIDateLayoutWithContext:] + 6568   UIKit                               0x0000000110af0ad9 -[UICollectionVIEwLayout invalIDateLayoutWithContext:] + 1899   UIKit                               0x0000000110afe2cc -[UICollectionVIEwFlowLayout invalIDateLayoutWithContext:] + 60410  libdispatch.dylib                   0x0000000114257d9d _dispatch_call_block_and_release + 1211  libdispatch.dylib                   0x00000001142783eb _dispatch_clIEnt_callout + 812  libdispatch.dylib                   0x00000001142601ef _dispatch_main_queue_callback_4CF + 173813  CoreFoundation                      0x00000001124f60f9 __CFRUNLOOP_IS_SERviciNG_THE_MAIN_disPATCH_QUEUE__ + 914  CoreFoundation                      0x00000001124b7b99 __CFRunLoopRun + 207315  CoreFoundation                      0x00000001124b70f8 CFRunLoopRunspecific + 48816  GraphiCSServices                    0x0000000114bcaad2 GSEventRunModal + 16117  UIKit                               0x000000011024cf09 UIApplicationMain + 17118  market-touch                        0x000000010d4cc472 main + 11419  libdyld.dylib                       0x00000001142ac92d start + 120  ???                                 0x0000000000000001 0x0 + 1)libc++abi.dylib: terminating with uncaught exception of type NSException

这是stack trace(略有不同的版本here).

为什么会发生这种情况,我能做些什么来防止这种情况发生?

编辑:
根据Doro的请求,这是我的cellForRowAtIndexPath:

func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell {    let cell = tableVIEw.dequeueReusableCellWithIDentifIEr(customCellNibname,forIndexPath: indexPath) as! CustomtableVIEwCell    //populating cell with data    return cell }

我根本不调用func setCollectionVIEwLayout(_ layout:UICollectionVIEwLayout,animated animated:Bool).

流程布局设置在IB中完成.

如果有的话,启用僵尸对象对我没什么帮助.这是我得到的堆栈跟踪:

-[NSIndexPath frame]: unrecognized selector sent to instance 0xc000000012de4890*** Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: '-[NSIndexPath frame]: unrecognized selector sent to instance 0xc000000012de4890'*** First throw call stack:(0x1815f6db0 0x180c5bf80 0x1815fdc4c 0x1815fabec 0x1814f8c5c 0x186fcccc0 0x186f9e688 0x1868de558 0x1868da0a4 0x1869ae9ec 0x1024f9a7c 0x1024f9a3c 0x1024ff4e4 0x1815acd50 0x1815aabb8 0x1814d4c50 0x182dbc088 0x1867b6088 0x1000c9f58 0x1810728b8)libc++abi.dylib: terminating with uncaught exception of type NSException

编辑2:

在我的CustomtableVIEwCell的awakeFromNib()方法中,我有以下代码:

if let layout = collectionVIEw.collectionVIEwLayout as? UICollectionVIEwFlowLayout {    layout.estimatedItemSize = CGSizeMake(50,22)}

我注意到,如果我发表评论,我就不会再遇到崩溃(尽管有时整个表视图会冻结并且无法使用).但是,集合视图单元格的大小不正确.比较:right对比wrong.

在IB中,集合视图流程布局 – >物品尺寸为50×22.用于集合视图的单元格中有一个按钮,高度约束为22pt.以下是为集合视图单元格设置布局属性的方法:

overrIDe func preferredLayoutAttributesFittingAttributes(layoutAttributes: UICollectionVIEwLayoutAttributes) -> UICollectionVIEwLayoutAttributes {    let attributes = super.preferredLayoutAttributesFittingAttributes(layoutAttributes)    button.setTitle(symbol,forState: .normal)    button.sizetoFit()    attributes.frame = button.frame    return attributes}

我们的想法是让这些细胞高22pt,宽度不同(约50pt),它们之间的距离相同.我可以在不调用代码的情况下实现这一点,当注释掉时,可以防止崩溃吗?

解决方法 结帐 this教程.

基本上,这可能是因为UItableVIEwCell的可重用必要条件.滚动tableVIEw时,它使用相同的可见单元格集,并从您的cellForRowAtIndexPath:方法设置内容.

根据您的实现,似乎在特定时间点取消分配UICollectionVIEwFlowLayout.我的意思是,你有电话

func setCollectionVIEwLayout(_ layout: UICollectionVIEwLayout,animated animated: Bool)

在cellForRowAtIndexPath中:在滚动时,新的UICollectionVIEwLayout被分配并设置为单元格内的collectionVIEw.在编辑方案中启用ZombIE对象 – >诊断 – >启用ZombIE Objects.检查当前状态的正确性.

很难建议任何工作片段,但作为一个想法,尝试在uitablevIEwCell的init方法中设置与流布局相关的所有属性(仅一次),这将避免重新分配:

-(UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static Nsstring *CellIDentifIEr = @"CellIDentifIEr";    UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr];    if (!cell)    {        cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:CellIDentifIEr];        // set your flow layout or other stuff here    }    return cell;}

希望这可以帮助.

总结

以上是内存溢出为你收集整理的ios – 使用带有FlowLayout的UICollectionView的单元格滚动UITableView时,应用程序崩溃全部内容,希望文章能够帮你解决ios – 使用带有FlowLayout的UICollectionView的单元格滚动UITableView时,应用程序崩溃所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1003039.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存