我得到:由于未捕获的异常而终止应用程序' NSInvalidUnarchiveOperationException',原因:'无法实例化名为(null)的类'

时间:2016-07-15 14:05:13

标签: ios iphone crash

我有一个集合视图,其中我加载了在xib中设计的单元格,我正在使用自动布局。在多个集合视图中使用相同的单元格。创建集合视图后,我正在执行以下操作

UINib* nib = [UINib nibWithNibName:@"Cell1" bundle:nil];
[collectionView registerNib:nib forCellWithReuseIdentifier:@"cell1"];

我正在按照以下方式创建单元格

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
 NSInteger count = [_products count];
    Cell1* cell = (Cell1*)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
    if(_products != nil)
    {
        [cell updateCell:_products[indexPath.item % count]];
    }
    return cell;
}

但是当它出现在单元格中时,我会遇到崩溃。请注意,这种崩溃并不总是发生,它会像100次一样发生。我检查了IBOutlets和约束,它们都是正确的。

  

特定应用信息:   ***由于未捕获的异常终止应用程序' NSInvalidUnarchiveOperationException',原因:'无法实例化名为(null)的类'

     

Last Exception Backtrace:CoreFoundation
  0x00000001840402d8 __exceptionPreprocess + 132 libobjc.A.dylib
  0x0000000195cbc0e0 objc_exception_throw + 56 CoreFoundation
  0x0000000184040214 + [NSException raise:format:] + 124 UIKit
  0x0000000188fa3394 0x188aa8000 + 376 UIKit
  0x0000000188fa3200 - [UINibDecoder decodeObjectForKey:] + 340 UIKit
  0x0000000188e2dcb4 - [UILabel initWithCoder:] + 700 UIKit
  0x0000000188fa3544 0x188aa8000 + 808 UIKit
  0x0000000188fa34e4 UINibDecoderDecodeObjectForValue + 712 UIKit
  0x0000000188fa3200 - [UINibDecoder decodeObjectForKey:] + 340 UIKit
  0x0000000188d80d40 - [UIView initWithCoder:] + 624 UIKit
  0x0000000188fa3544 0x188aa8000 + 808 UIKit
  0x0000000188fa34e4 UINibDecoderDecodeObjectForValue + 712 UIKit
  0x0000000188fa3200 - [UINibDecoder decodeObjectForKey:] + 340 UIKit
  0x0000000188d80d40 - [UIView initWithCoder:] + 624 UIKit
  0x00000001891504ac - [UICollectionReusableView initWithCoder:] + 52   UIKit 0x0000000189150738    - [UICollectionViewCell initWithCoder:] + 60 UIKit 0x0000000188ed95a8 - [UIClassSwapper initWithCoder:] + 232 UIKit
  0x0000000188fa3544 0x188aa8000 + 808 UIKit
  0x0000000188fa3200 - [UINibDecoder decodeObjectForKey:] + 340 UIKit
  0x0000000188ed90b0 - [UIRuntimeConnection initWithCoder:] + 124 UIKit
  0x0000000188fa3544 0x188aa8000 + 808 UIKit
  0x0000000188fa34e4 UINibDecoderDecodeObjectForValue + 712 UIKit
  0x0000000188fa3200 - [UINibDecoder decodeObjectForKey:] + 340 UIKit
  0x0000000188ed8538 - [UINib instantiateWithOwner:options:] + 1096 UIKit   0x0000000189142b80 - [UICollectionView   _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 792 UIKit 0x000000018243de58 0x182408000 + 220760 Clubcard 0x000000010016dcbc    - [CollectionDataSourceSecond collectionView:cellForItemAtIndexPath:](CollectionDataSourceSecond.m:91)

任何帮助将不胜感激。

0 个答案:

没有答案