2016-05-27 5 views
4

このアプリはXcode 7.3.1を使用してSwift 2.2で記述されています。FlowLayoutを持つUICollectionViewを持つセルでUITableViewをスクロールするとアプリケーションがクラッシュする

私は、のUICollectionViewのセルを持つUITableViewを持っています。私はテーブルをスクロールするときアップ表示し、ダウン本当に速いし、それがAppDelegateで

EXC_BAD_ACCESS 

とデバイス(iPadのエアー2、iOSの9.3.2)またはシミュレータ、アプリのクラッシュに停止させることなく。

このアプリケーションでは、ビューコントローラで設定したブレークポイントにdidReceiveMemoryWarning()のヒットしていません。

コードがアプリケーションコードの任意の行に私を指していない

0_dispatch_barrier_async_f_slow. 

スタックトレースが続く

[UICollectionViewData invalidateItemsAtIndexPaths:] 

または

[_UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:] 

にクラッシュするようです。シミュレータ用

コンソールのスタックトレース(デバイス上でクラッシュしていないコンソールスタックトレース):

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[_UIFlowLayoutItem frame]: unrecognized selector sent to class 0x110f9ecc0' 
*** First throw call stack: 
(
0 CoreFoundation      0x000000011259cd85 __exceptionPreprocess + 165 
1 libobjc.A.dylib      0x00000001137d3deb objc_exception_throw + 48 
2 CoreFoundation      0x00000001125a5c3d +[NSObject(NSObject) doesNotRecognizeSelector:] + 205 
3 CoreFoundation      0x00000001124ebcfa ___forwarding___ + 970 
4 CoreFoundation      0x000000011259e1f8 __forwarding_prep_1___ + 120 
5 UIKit        0x0000000110b1d8b5 -[UICollectionViewData invalidateItemsAtIndexPaths:] + 273 
6 UIKit        0x0000000110ae26b7 -[UICollectionView _invalidateWithBlock:] + 62 
7 UIKit        0x0000000110ae2a6f -[UICollectionView _invalidateLayoutWithContext:] + 656 
8 UIKit        0x0000000110af0ad9 -[UICollectionViewLayout invalidateLayoutWithContext:] + 189 
9 UIKit        0x0000000110afe2cc -[UICollectionViewFlowLayout invalidateLayoutWithContext:] + 604 
10 libdispatch.dylib     0x0000000114257d9d _dispatch_call_block_and_release + 12 
11 libdispatch.dylib     0x00000001142783eb _dispatch_client_callout + 8 
12 libdispatch.dylib     0x00000001142601ef _dispatch_main_queue_callback_4CF + 1738 
13 CoreFoundation      0x00000001124f60f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 
14 CoreFoundation      0x00000001124b7b99 __CFRunLoopRun + 2073 
15 CoreFoundation      0x00000001124b70f8 CFRunLoopRunSpecific + 488 
16 GraphicsServices     0x0000000114bcaad2 GSEventRunModal + 161 
17 UIKit        0x000000011024cf09 UIApplicationMain + 171 
18 market-touch      0x000000010d4cc472 main + 114 
19 libdyld.dylib      0x00000001142ac92d start + 1 
20 ???         0x0000000000000001 0x0 + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

はここstack trace(わずかに異なるバージョンhere)です。

なぜそれが起こっているのですか、それを防ぐために何ができるのですか?

編集:私は全然func setCollectionViewLayout(_ layout: UICollectionViewLayout, animated animated: Bool)を呼び出すことはありません

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCellWithIdentifier(customCellNibName, forIndexPath: indexPath) as! CustomTableViewCell 

    //populating cell with data 

    return cell 
} 

Doroの要求を1として、ここに私のcellForRowAtIndexPathです。

フローレイアウトの設定は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 

EDIT 2:私のCustomTableViewCellの私は、次のコードを持っているawakeFromNib()方法で

:ここでスタック私が得た跡がある

if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout { 
    layout.estimatedItemSize = CGSizeMake(50, 22) 
} 

私は私がいることをコメントした場合ということに気づきましたテーブルビュー全体がフリーズして使用できなくなることもありますが、クラッシュすることはもうありません。ただし、コレクションビューセルののサイズが正しくない場合はとなります。比較:rightwrong

IBでは、コレクションビューフローレイアウト - >アイテムサイズは50x22です。コレクションビューに使用されるセルには、1つのボタンがあり、高さの制約は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前後)の幅を変えることが持っていることです。コメントアウトしたときにクラッシュを防止するコードを呼び出すことなく、これを達成できますか?

+0

あなたのcellForRowAtIndexPathを共有してください。それはより良い理解を与えるだろう – Doro

答えて

0

チェックアウトthisチュートリアル。

基本的に、これはUITableViewCellの再利用可能な必須機能のために発生する可能性があります。 tableViewをスクロールすると、同じ一連の表示セルが使用され、cellForRowAtIndexPath:メソッドのコンテンツが設定されます。

実装によっては、特定の時点でUICollectionViewFlowLayoutの割り当てが解除されているようです。私は意味、あなたはcellForRowAtIndexPath:

func setCollectionViewLayout(_ layout: UICollectionViewLayout, 
        animated animated: Bool) 

に呼び出す必要があり、あなたがスクロールしている間に、新しいUICollectionViewLayoutが割り当てられ、あなたの細胞内部collectionViewに設定されています。 [Edit Scheme] - > [Diagnostics] - > [Enable 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; 
} 

お役に立てれば。

関連する問題