objective-c - CollectionView iOS 7 问题

标签 objective-c ios7 uicollectionview

我的 collectionView 有问题,在 iOS 6 中该项目运行良好,但是当我将部署目标更改为 iOS 7 时,该项目不再运行。

**Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:cellForItemAtIndexPath: (<NSIndexPath: 0x8daa110> {length = 2, path = 0 - 0}) was not retrieved by calling -dequeueReusableCellWithReuseIdentifier:forIndexPath: or is nil (<CustomCollecionCell: 0x8dab520; baseClass = UICollectionViewCell; frame = (0 0; 300 190); clipsToBounds = YES; opaque = NO; autoresize = RM+TM; layer = <CALayer: 0x8daad00>>)'
*** First throw call stack:
(
    0   CoreFoundation                      0x029405e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01de88b6 objc_exception_throw + 44
    2   CoreFoundation                      0x02940448 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x017bbfee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    4   UIKit                               0x00f5bd81 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 698
    5   UIKit                               0x00f6f19f __51-[UICollectionView _viewAnimationsForCurrentUpdate]_block_invoke1144 + 521
    6   UIKit                               0x00f6c793 -[UICollectionView _viewAnimationsForCurrentUpdate] + 2901
    7   UIKit                               0x00f6ff9c -[UICollectionView _updateWithItems:] + 1635
    8   UIKit                               0x00f6b978 -[UICollectionView _endItemAnimations] + 14317
    9   UIKit                               0x00f67f95 -[UICollectionView _updateRowsAtIndexPaths:updateAction:] + 361
    10  UIKit                               0x00f67fdc -[UICollectionView insertItemsAtIndexPaths:] + 48
    11  Home Automation                     0x0004d541 -[MainDashboardViewController stopDragging:] + 6209
    12  Home Automation                     0x00049117 -[MainDashboardViewController handlePanning:] + 215
    13  UIKit                               0x00cc1e8c _UIGestureRecognizerSendActions + 230
    14  UIKit                               0x00cc0b00 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
    15  UIKit                               0x00cc256d -[UIGestureRecognizer _delayedUpdateGesture] + 60
    16  UIKit                               0x00cc5acd ___UIGestureRecognizerUpdate_block_invoke + 57
    17  UIKit                               0x00cc5a4e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
    18  UIKit                               0x00cbc148 _UIGestureRecognizerUpdate + 199
    19  UIKit                               0x0098819a -[UIWindow _sendGesturesForEvent:] + 1291
    20  UIKit                               0x009890ba -[UIWindow sendEvent:] + 1030
    21  UIKit                               0x0095ce86 -[UIApplication sendEvent:] + 242
    22  UIKit                               0x0094718f _UIApplicationHandleEventQueue + 11421
    23  CoreFoundation                      0x028c983f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    24  CoreFoundation                      0x028c91cb __CFRunLoopDoSources0 + 235
    25  CoreFoundation                      0x028e629e __CFRunLoopRun + 910
    26  CoreFoundation                      0x028e5ac3 CFRunLoopRunSpecific + 467
    27  CoreFoundation                      0x028e58db CFRunLoopRunInMode + 123
    28  GraphicsServices                    0x032d69e2 GSEventRunModal + 192
    29  GraphicsServices                    0x032d6809 GSEventRun + 104
    30  UIKit                               0x00949d3b UIApplicationMain + 1225
    31  Home Automation                     0x0000295d main + 141
    32  libdyld.dylib                       0x02534725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException


--------------------------------------------------------------------------------------**

注意:我有两个具有不同 customCell 类的 collectionView。

最佳答案

从 iOS 7 开始,您需要为您使用的每个 collectionviewcell 注册一个 nib/class,并在中调用 dequeue 方法

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;

由您的 UICollectionViewDataSource 实现。

所以首先调用以下方法之一(例如在 viewDidLoad 中):

- (void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;

然后使用

- (id)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath*)indexPath;

实例化 cellForItemAtIndexPath 中的实际单元格。

关于objective-c - CollectionView iOS 7 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19925580/

相关文章:

ios - 如何减少 collectionviewcell 和 collection view 之间的顶部空间

ios - 删除 restKit 0.20 中的孤立对象

ios - 终止后启动iOS 7重大位置更改

ios - 点击按钮时如何隐藏 collectionView header ?

jquery - iOS7 中 jQuery Mobile 滑动事件的不稳定行为

ios - 如何使用仅返回后缀数字的函数扩展 NSString?

ios - UICollectionView 边界线不存在黑色背景

objective-c - 在 Swift 中使用一个返回 Optional 或 Throw 的 Objective-C 函数

iphone - "UIScreen mainScreen] applicationFrame]"横向模式

ios - 关闭并再次出现后自定义 UIView Controller 中的 NSNotificationCenter 错误