UICollectionViewController无法在升级的XCode 7项目

时间:2016-03-14 11:04:33

标签: ios xcode swift uicollectionview

我正在开发一个使用故事板的项目,它是在XCode 6中启动的,并且已经升级到XCode 7.我正在尝试添加一个UICollectionViewController。我在这一行得到例外:let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! UnsplashCollectionViewCell

我已经验证控制器和单元都已分配给故事板中的自定义类,并且我的重用标识符已分配给单元格,并且与我的控制器类中的变量reuseIdentifier相同。

关于我在工作的UICollectionViewController和这个项目之间的唯一区别是,如果我启动一个新项目并添加一个UICollectionViewController,我在Connections Inspector中得到以下内容: Working - New Project

但是,我破坏的项目中的Connections Inspector如下所示: Not Working - Upgraded Project

我不确定这是不是问题,但我不知道还有什么可能。

崩溃日志:

  

未捕获的异常:无法使类型的视图出列:具有标识符UnsplashCell的UICollectionElementKindCell - 必须为标识符注册nib或类或在故事板中连接原型单元

Cell Inspectors

完整崩溃日志:

2016-03-14 10:34:55.027 PixelSquidTouch[86881:2845927] [Crashlytics] Version 3.4.1 (92)
2016-03-14 10:34:55.063 PixelSquidTouch[86881:]  App measurement v.1201000 started
2016-03-14 10:35:02.990 PixelSquidTouch[86881:2845927] *** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UICollectionView.m:3690
2016-03-14 10:35:03.013 PixelSquidTouch[86881:2845927] WARNING: GoogleAnalytics 3.14 void GAIUncaughtExceptionHandler(NSException *) (GAIUncaughtExceptionHandler.m:48): Uncaught exception: could not dequeue a view of kind: UICollectionElementKindCell with identifier UnsplashCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
2016-03-14 10:35:08.054 PixelSquidTouch[86881:2845927] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier UnsplashCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010c95ce65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010ffb0deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010c95ccca +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x000000010fa274de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
    4   UIKit                               0x000000010ddd04e9 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 2009
    5   UIKit                               0x000000010ddd0945 -[UICollectionView dequeueReusableCellWithReuseIdentifier:forIndexPath:] + 169
    6   PixelSquidTouch                     0x000000010b8d9e6a _TFC15PixelSquidTouch32UnsplashCollectionViewController14collectionViewfS0_FTCSo16UICollectionView22cellForItemAtIndexPathCSo11NSIndexPath_CSo20UICollectionViewCell + 122
    7   PixelSquidTouch                     0x000000010b8d9f8f _TToFC15PixelSquidTouch32UnsplashCollectionViewController14collectionViewfS0_FTCSo16UICollectionView22cellForItemAtIndexPathCSo11NSIndexPath_CSo20UICollectionViewCell + 79
    8   UIKit                               0x000000010ddc05ba -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:] + 483
    9   UIKit                               0x000000010ddc2ae0 -[UICollectionView _updateVisibleCellsNow:] + 4431
    10  UIKit                               0x000000010ddc723b -[UICollectionView layoutSubviews] + 247
    11  UIKit                               0x000000010d6224a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
    12  QuartzCore                          0x000000010f41759a -[CALayer layoutSublayers] + 146
    13  QuartzCore                          0x000000010f40be70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    14  QuartzCore                          0x000000010f40bcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    15  QuartzCore                          0x000000010f400475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    16  QuartzCore                          0x000000010f42dc0a _ZN2CA11Transaction6commitEv + 486
    17  UIKit                               0x000000010d596b47 _afterCACommitHandler + 174
    18  CoreFoundation                      0x000000010c888367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    19  CoreFoundation                      0x000000010c8882d7 __CFRunLoopDoObservers + 391
    20  CoreFoundation                      0x000000010c87df2b __CFRunLoopRun + 1147
    21  CoreFoundation                      0x000000010c87d828 CFRunLoopRunSpecific + 488
    22  GraphicsServices                    0x000000011197cad2 GSEventRunModal + 161
    23  UIKit                               0x000000010d56b610 UIApplicationMain + 171
    24  PixelSquidTouch                     0x000000010b957aad main + 109
    25  libdyld.dylib                       0x0000000110b5692d start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

CollectionViewController hierarchy

2 个答案:

答案 0 :(得分:1)

因此,您正在尝试将单元格出列但没有具有该ID的单元格。您需要在情节提要或Xib中打开单元格,并将UICollectionElementKindCell ID设置为该ID UnsplashCell

如果您没有将故事板中的单元格作为原型单元格进行处理,但是正在使用xib文件,那么您还需要使用tableview注册该单元格,以便它知道单元格类型。

在viewDidLoad中:

let nibName = UINib(nibName: "UICollectionElementKindCell", bundle:nil)
self.tableView.registerNib(nibName, forCellReuseIdentifier: "UnsplashCell")

更新

在选择VC的情况下查看故事板中的对象出口等。 enter image description here

答案 1 :(得分:0)

自上周升级到XCode 7以来,我也在努力解决同样的问题。在我们的例子中,每当我们显示活动视图时,我们都会禁用用户交互:

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

然后,在回调块中,我们重新启用了用户与此的交互:

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

删除这些调用解决了我们的代码中的四个问题中的三个;希望它也能解决你的问题。无论如何,我们还没有提出更好的方法。