UICollectionView在xcode16编译闪退问题

使用xcode15运行工程,控制台会出现如下提示:

Expected dequeued view to be returned to the collection view in preparation for display. When the collection view's data source is asked to provide a view for a given index path, ensure that a single view is dequeued and returned to the collection view. Avoid dequeuing views without a request from the collection view. For retrieving an existing view in the collection view, use -[UICollectionView cellForItemAtIndexPath:] or -[UICollectionView supplementaryViewForElementKind:atIndexPath:]. Dequeued view: <IQEngUICollectionViewCell: 0x130215e00; baseClass = UICollectionViewCell; frame = (396 0; 396 98.1547); clipsToBounds = YES; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x301e371a0>>; Collection view: <UICollectionView: 0x1300caa00; frame = (0 0; 396 98.1547); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x300b706f0>; backgroundColor = <UIDynamicSystemColor: 0x3002a3380; name = systemBackgroundColor>; layer = <CALayer: 0x301d5a080>; contentOffset: {0, 0}; contentSize: {3168, 98.154666666666671}; adjustedContentInset: {0, 0, 0, 0}; layout: <IQEngCollectionViewFlowLayout: 0x1237e7480>; dataSource: IQEngCarouselView:<IQEngCarouselView: 0x130117e00; frame = (16 11.4133; 396 98.1547); clipsToBounds = YES; layer = <CALayer: 0x301d59f20>>> This will become an assert in a future version.

然后在xcode16运行是会直接闪退的,控制台会显示

*** Assertion failure in -[UICollectionView _updateVisibleCellsNow:], UICollectionView.m:5673

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Expected dequeued view to be returned to the collection view in preparation for display. When the collection view's data source is asked to provide a view for a given index path, ensure that a single view is dequeued and returned to the collection view. Avoid dequeuing views without a request from the collection view. For retrieving an existing view in the collection view, use -[UICollectionView cellForItemAtIndexPath:] or -[UICollectionView supplementaryViewForElementKind:atIndexPath:]. Dequeued view: <IQEngUICollectionViewCell: 0x1627b4780; baseClass = UICollectionViewCell; frame = (396 0; 396 98.1547); clipsToBounds = YES; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x302bc77a0>>; Collection view: <UICollectionView: 0x15fd0c000; frame = (0 0; 396 98.1547); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x3030c4570>; backgroundColor = <UIDynamicSystemColor: 0x303a1f880; name = systemBackgroundColor>; layer = <CALayer: 0x302663260>; contentOffset: {0.33333333333333331, 0}; contentSize: {3168, 98.154666666666671}; adjustedContentInset: {0, 0, 0, 0}; layout: <IQEngCollectionViewFlowLayout: 0x15fb53480>; dataSource: IQEngCarouselView:<IQEngCarouselView: 0x15fcab800; frame = (16 11.4133; 396 98.1547); clipsToBounds = YES; layer = <CALayer: 0x3026630a0>>>'

问题原因在于,轮播图在自动轮播的时候调用的方法有问题

objectivec 复制代码
这个代码是有问题的    
UICollectionViewCell *cell = [self collectionView:self.collectionView cellForItemAtIndexPath:indexPath];
    CGFloat f1_minX = cell.frame.origin.x;
    CGPoint point = CGPointZero;
    point.x = f1_minX;
    CGPoint nextPoint = [self.collectionViewLayout targetContentOffsetForProposedContentOffset:point withScrollingVelocity:CGPointZero];
    [self.collectionView setContentOffset:nextPoint animated:animated];

将上面代码换成

objectivec 复制代码
    [self.collectionView scrollToItemAtIndexPath:indexPath
                                atScrollPosition:UICollectionViewScrollPositionLeft
                                        animated:animated];

可以解决问题

相关推荐
_可乐无糖19 小时前
Appium 检查安装的驱动
android·ui·ios·appium·自动化
胖虎11 天前
iOS 网络请求: Alamofire 结合 ObjectMapper 实现自动解析
ios·alamofire·objectmapper·网络请求自动解析·数据自动解析模型
开发者如是说1 天前
破茧英语路:我的经验与自研软件
ios·创业·推广
假装自己很用心2 天前
iOS 内购接入StoreKit2 及低与iOS 15 版本StoreKit 1 兼容方案实现
ios·swift·storekit·storekit2
iOS阿玮2 天前
“小红书”海外版正式更名“ rednote”,突然爆红的背后带给开发者哪些思考?
ios·app·apple
刘小哈哈哈2 天前
iOS UIScrollView的一个特性
macos·ios·cocoa
丁乾坤的博客2 天前
function isBulkReadStatement, file SQLiteDatabaseTracking.cpp
mysql·xcode16·ios18闪退
忆江南的博客3 天前
iOS 性能优化:实战案例分享
ios
忆江南的博客3 天前
深入剖析iOS网络优化策略,提升App性能
ios
一丝晨光4 天前
GCC支持Objective C的故事?Objective-C?GCC只能编译C语言吗?Objective-C 1.0和2.0有什么区别?
c语言·开发语言·ios·objective-c·msvc·clang·gcc