collectionview cell丢失的问题

本文介绍了一种在项目开发过程中遇到的问题:UICollectionView的部分cell在特定条件下无法显示。通过逐步排查,发现是由于前一个section的size设置为0导致后续section的cell加载失败。最终解决方案是将number而非size设置为0。

1. 发现问题

项目开发中遇到了问题,一个商品详情底下的商品列表,部分情况下前几个cell怎么也不显示

就是方法明明写的都没错,就是前几个cell丢失

2. 查找问题

首先从cell方法寻找,发现根本没走
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

然后依次把前几个section的size给0,发现没用

再然后把number给0,发现好了

  • 问题在于,前一个section的number不是0 但是size是0

3. 解决问题

直接把number给0,而不是size给0

4. 制作demo

上图:

图片地址

  • 其中左边是不正常(第一个section导致第二个section不读取)
  • 右边的是正常

demoURL,在git上

已经向苹果发邮件请教…

override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) if isFromClickNotification { self.tpNavigationController?.interactivePopGestureRecognizer?.isEnabled = false let screenGesture = UIScreenEdgePanGestureRecognizer.init(target: self, action: #selector(handleEdgeLeftGesture)) screenGesture.delegate = self screenGesture.edges = UIRectEdge.left self.view.addGestureRecognizer(screenGesture) } mediaPlayerWindowViewController.setPlaybackType(Int(TPSS_MP_PLAYBACK_TYPE_MSG_PLAYBACK)) if isFirst { isFirst = false } else { // mediaPlayerWindowViewController.upgradeForegroundWindows(false, false, calendar.date(from: playbackTime as DateComponents)!.timeIntervalSince1970) self.changeMessagePlayingIndex(from: IndexPath.init(row: currentMessageIndex, section: 0)) flowWindowView.setFlowLabel(speed: 0, content: mediaPlayerWindowViewController.getDataRecevied()) } if isCloudVMS || isLocalVms { if(currentMessageIndex < siteMessageArray.count){ self._collectionView?.scrollToItem(at: IndexPath.init(row: currentMessageIndex, section: 0), at: .centeredVertically, animated: true) } } else { if(currentMessageIndex < viewModel.rowCountForSections[0]){ self._collectionView?.scrollToItem(at: IndexPath.init(row: currentMessageIndex, section: 0), at: .centeredVertically, animated: true) } } //更新播放倍速 self.updatePlaySpeed(numerator: speedNumerator, denominator: speedDenominator) DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.5) { self.showVisibleAreaCells() if self.appContext.isVmsLogin { self.preconnectToRelay(devId: self.windowConfig?.identifier ?? self.device.identifier, siteId: Int64(self.currentVmsMessage?.siteID ?? 0), channelId: self.windowConfig?.channelId ?? -1, isPreview: false) } } }
最新发布
10-15
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值