gpt4 book ai didi

objective-c - CollectionView iOS 7 问题

转载 作者:搜寻专家 更新时间:2023-10-30 19:43:57 31 4
gpt4 key购买 nike

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

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com