0

アプリが[NSObject(NSObject) doesNotRecognizeSelector:]でクラッシュすることがあります。セレクタは[UIImageView setImage:]です。[NSObject(NSObject)doesNotRecognizeSelector:]でアプリがクラッシュするのはなぜですか?

enter image description here

私は例外ブレークポイントを設定することにより、それを捕獲し、UICollectionViewCellprepareForReuseUIImageView.imageを設定するときにクラッシュが起こる:

class MyCell: UICollectionViewCell { 

    var coverImageView = UIImageView() 

    ... 

    override func prepareForReuse() { 
     super.prepareForReuse() 

     coverImageView.image = nil 
    } 
} 

prepareForReuseは、細胞がインスタンス化された後に呼び出されます。

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 

    let cell = myCollectionView.dequeueReusableCell(withReuseIdentifier: "myReuseID", for: indexPath) as! MyCell 
    ... 
} 

どうしてですか?

また、UIImageViewのクイックルックデータビューを読み込むことができないため、オブジェクトがリリースされている可能性がありますか?

enter image description here

コンソールでのエラーメッセージは、次のとおりです。

2017-01-21 15:56:19.653 MyApp[4873:20387361] -[__NSMallocBlock__ size]: unrecognized selector sent to instance 0x608000880aa0 
2017-01-21 15:56:37.697 MyApp[4873:20387361] invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution. 

2017-01-21 15:56:38.847 MyApp[4873:20617657] [Optimizely Logging]: Successfully saved data file to disk. Code revision is 229 
2017-01-21 15:56:42.723 MyApp[4873:20387361] [Optimizely Logging]: (ERROR) NSInvalidArgumentException: Stack Trace: 
(
    0 CoreFoundation      0x000000010f587d4b __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x000000010ef6121e objc_exception_throw + 48 
    2 CoreFoundation      0x000000010f5f7f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 
    3 CoreFoundation      0x000000010f50d005 ___forwarding___ + 1013 
    4 CoreFoundation      0x000000010f50cb88 _CF_forwarding_prep_0 + 120 
    5 UIKit        0x000000010ba5e20f -[UIImageView _updateImageViewForOldImage:newImage:] + 297 
    6 UIKit        0x000000010ba59950 -[UIImageView setImage:] + 391 
    7 MyApp        0x000000010945e0d8 _TFC6MyApp23MyCell15prepareForReusefT_T_ + 136 
    8 MyApp        0x000000010945e112 _TToFC6MyApp23MyCell15prepareForReusefT_T_ + 34 
    9 UIKit        0x000000010c19aed1 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 773 
    10 UIKit        0x000000010c19b8ea -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 169 
    11 MyApp        0x00000001095bdee2 _TFC6MyApp23MyViewController14collectionViewfTCSo16UICollectionView13cellForItemAtV10Foundation9IndexPath_CSo20UICollectionViewCell + 594 
    12 MyApp        0x00000001095be747 _TToFC6MyApp23MyViewController14collectionViewfTCSo16UICollectionView13cellForItemAtV10Foundation9IndexPath_CSo20UICollectionViewCell + 87 
    13 UIKit        0x000000010c18675f -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 467 
    14 UIKit        0x000000010c186586 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 35 
    15 UIKit        0x000000010c18ba5e -[UICollectionView _updateVisibleCellsNow:] + 4803 
    16 UIKit        0x000000010c191725 -[UICollectionView layoutSubviews] + 313 
    17 UIKit        0x000000010b90dab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237 
    18 QuartzCore       0x000000010d558bf8 -[CALayer layoutSublayers] + 146 
    19 QuartzCore       0x000000010d54c440 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 
    20 QuartzCore       0x000000010d54c2be _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 
    21 QuartzCore       0x000000010d4da318 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280 
    22 QuartzCore       0x000000010d5073ff _ZN2CA11Transaction6commitEv + 475 
    23 QuartzCore       0x000000010d507d6f _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113 
    24 CoreFoundation      0x000000010f52c267 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 
    25 CoreFoundation      0x000000010f52c1d7 __CFRunLoopDoObservers + 391 
    26 CoreFoundation      0x000000010f510f8e __CFRunLoopRun + 1198 
    27 CoreFoundation      0x000000010f510884 CFRunLoopRunSpecific + 420 
    28 GraphicsServices     0x0000000112b77a6f GSEventRunModal + 161 
    29 UIKit        0x000000010b848c68 UIApplicationMain + 159 
    30 MyApp        0x00000001092f5a7f main + 111 
    31 libdyld.dylib      0x00000001115b568d start + 1 
) 
2017-01-21 15:56:42.725 MyApp[4873:20387361] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSMallocBlock__ size]: unrecognized selector sent to instance 0x608000880aa0' 
*** First throw call stack: 
(
    0 CoreFoundation      0x000000010f587d4b __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x000000010ef6121e objc_exception_throw + 48 
    2 CoreFoundation      0x000000010f5f7f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 
    3 CoreFoundation      0x000000010f50d005 ___forwarding___ + 1013 
    4 CoreFoundation      0x000000010f50cb88 _CF_forwarding_prep_0 + 120 
    5 UIKit        0x000000010ba5e20f -[UIImageView _updateImageViewForOldImage:newImage:] + 297 
    6 UIKit        0x000000010ba59950 -[UIImageView setImage:] + 391 
    7 MyApp        0x000000010945e0d8 _TFC6MyApp23MyCell15prepareForReusefT_T_ + 136 
    8 MyApp        0x000000010945e112 _TToFC6MyApp23MyCell15prepareForReusefT_T_ + 34 
    9 UIKit        0x000000010c19aed1 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 773 
    10 UIKit        0x000000010c19b8ea -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 169 
    11 MyApp        0x00000001095bdee2 _TFC6MyApp23MyViewController14collectionViewfTCSo16UICollectionView13cellForItemAtV10Foundation9IndexPath_CSo20UICollectionViewCell + 594 
    12 MyApp        0x00000001095be747 _TToFC6MyApp23MyViewController14collectionViewfTCSo16UICollectionView13cellForItemAtV10Foundation9IndexPath_CSo20UICollectionViewCell + 87 
    13 UIKit        0x000000010c18675f -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 467 
    14 UIKit        0x000000010c186586 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 35 
    15 UIKit        0x000000010c18ba5e -[UICollectionView _updateVisibleCellsNow:] + 4803 
    16 UIKit        0x000000010c191725 -[UICollectionView layoutSubviews] + 313 
    17 UIKit        0x000000010b90dab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237 
    18 QuartzCore       0x000000010d558bf8 -[CALayer layoutSublayers] + 146 
    19 QuartzCore       0x000000010d54c440 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 
    20 QuartzCore       0x000000010d54c2be _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 
    21 QuartzCore       0x000000010d4da318 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280 
    22 QuartzCore       0x000000010d5073ff _ZN2CA11Transaction6commitEv + 475 
    23 QuartzCore       0x000000010d507d6f _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113 
    24 CoreFoundation      0x000000010f52c267 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 
    25 CoreFoundation      0x000000010f52c1d7 __CFRunLoopDoObservers + 391 
    26 CoreFoundation      0x000000010f510f8e __CFRunLoopRun + 1198 
    27 CoreFoundation      0x000000010f510884 CFRunLoopRunSpecific + 420 
    28 GraphicsServices     0x0000000112b77a6f GSEventRunModal + 161 
    29 UIKit        0x000000010b848c68 UIApplicationMain + 159 
    30 MyApp        0x00000001092f5a7f main + 111 
    31 libdyld.dylib      0x00000001115b568d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
+0

たぶんXIBからその変数に割り当てられた別のクラスがある:

適切に指定イニシャライザを使用して、それは、UIImageViewを初期化する修正するには? – Sulthan

+0

クラッシュログには、0〜4のステップがありません。それも拡張できますか? – Sulthan

+0

@ Suulthan拡張することはできません。クラッシュログではなく、Xcoceのデバッグナビゲータです。また、 'setImage'はクラッシュするようなセレクターなので、ステップ1〜3はないと思います。 – Manuel

答えて

1

私はこの問題は、あなたが、UIImageViewの指定イニシャライザを呼び出していないため、そのimageプロパティが正しく初期化されていないとしようとしているということだと思いますそれに割り当てて、アプリをクラッシュさせます:

- [NSMallocBlockサイズ]:未認識セレクタインスタンスに0x608000880aa0

を送信する方法は、古い画像にsizeメソッドを呼び出そうが、古い画像がいくつかのランダムなメモリアドレスに設定しました。

var coverImageView = UIImageView(image: nil) 
+0

それは意味があります、私はそれを試みます。しかし、なぜpublic初期化子 'UIImageView(void)'があるのでしょうか?このようなクラッシュが起きた場合は、プライベートにしてはいけませんか? – Manuel

+1

@Manuelこれは 'NSObject'(および' UIView')から継承されています。 Objective-Cでは、初期化子の継承はSwiftのように単純ではありません。 – Sulthan

+0

私はそれを見て、それは時々だけクラッシュするとどのように解釈しますか? – Manuel

関連する問題