CollectionView iOS 7问题

4

我的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


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

注意:我有两个CollectionView,分别使用不同的自定义Cell类。

иҜ·еҸ‘еёғжӮЁзҡ„cellForRowAtIndexPathе’Ңе…¶д»–зӣёе…ід»Јз ҒгҖӮ - Timothy Moose
虽然这个日志没有提供太多细节,但我相信你的indexPath或数据源有问题,这是你创建集合视图的来源。请关注[UICollectionView insertItemsAtIndexPaths:] + 48 - Ganesh Somani
1个回答

3
自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中实例化实际的单元格。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接