当前位置: 首页 > article >正文

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>>>'

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

这个代码是有问题的    
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];

将上面代码换成

    [self.collectionView scrollToItemAtIndexPath:indexPath
                                atScrollPosition:UICollectionViewScrollPositionLeft
                                        animated:animated];

可以解决问题


http://www.kler.cn/a/415382.html

相关文章:

  • 计算机的错误计算(一百六十九)
  • Cesium K-means自动聚合点的原理
  • 第2.3 AI文本—prompt入门
  • Paddle Inference部署推理(一)
  • uniapp中使用uni-forms实现表单管理,验证表单
  • C语言——指针初阶(一)
  • 如何查看ubuntu服务器的ssh服务是否可用
  • 【浏览器】缓存与存储
  • Java WEB:从起源到现代的传奇之旅
  • Java项目中加缓存
  • 新合作!Babylon Labs、Lombard 和 Cubist 将可编程 BTC 引入Sui
  • Jenkins-基于 JNLP协议的 Java Web 启动代理
  • Python图像处理——Python转换h264格式视频
  • 链表?->?(以尾插法说明,附头插法)
  • 如何通过智能生成PPT,让演示文稿更高效、更精彩?
  • 游戏引擎学习第24天
  • MacOS 配置github密钥
  • 【Android】MMKV—高性能轻量化存储组件
  • Rust赋能前端:写一个 Excel 生成引擎
  • 未成年人模式护航,保障安全健康上网
  • M4V 视频是一种什么格式?如何把 M4V 转为 MP4 格式?
  • 【Linux】-学习笔记06
  • YOLOv9改进,YOLOv9引入CAS-ViT(卷积加自注意力视觉变压器)中AdditiveBlock模块,二次创新RepNCSPELAN4结构
  • TCGA 编码格式解读 | 怎么区分是不是肿瘤样品?
  • Langchain 实现 RAG
  • 韩国集运小卡业务:价格、包装、速度下的双赢策略