Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS11系统,偶发闪退 #18

Closed
Next-Future-X opened this issue Jun 25, 2021 · 11 comments
Closed

iOS11系统,偶发闪退 #18

Next-Future-X opened this issue Jun 25, 2021 · 11 comments

Comments

@Next-Future-X
Copy link

func scrollToIndexPath(_ indexPath: IndexPath, animated: Bool) { }
方法内部调用collectionView滚动方法,在系统版本低的设备上会触发闪退的情况。
断点分析为collectionView未刷新完成,调用scrollToItem导致。
解决办法:
我尝试在滚动之前,判断要求滚动到的index是否合法,且滚动到的位置是否有item,可以解决闪退问题
添加的判断代码如下:
guard collectionView.numberOfItems(inSection: indexPath.section) > indexPath.row, let _ = collectionView.dataSource?.collectionView(collectionView, cellForItemAt: indexPath) else { return }

image

@Coder-TanJX
Copy link
Owner

好的,非常感谢提醒,虽然目前没有条件复现,但是今天我会更新一下代码。

@Coder-TanJX
Copy link
Owner

测试了一下你提供的代码会产生错误,params.cycleWay == .forward时不能自动滚动。

@Next-Future-X
Copy link
Author

两个判断条件
第一 collectionView.numberOfItems(inSection: indexPath.section) > indexPath.row
第二 let _ = collectionView.dataSource?.collectionView(collectionView, cellForItemAt: indexPath)
请问是哪个条件卡住了

@Coder-TanJX
Copy link
Owner

可以帮我测试一下在:private func refreshData() 方法中使用下面代码吗?
placeholderImgView.isHidden = pageCount > 0
collectionView.performBatchUpdates {[weak self] in
self?.collectionView.reloadData()
} completion: { [weak self] _ in
self?.reinitializeIndexPath()
}

@Coder-TanJX
Copy link
Owner

对,就是第二个条件用这种循环滚动方式(params.cycleWay == .forward)会返回空。

@Next-Future-X
Copy link
Author

params.cycleWay == .forward 这样设置的情况下是吧

@Coder-TanJX
Copy link
Owner

对,然后你使用我提供你的代码 看一下能解决你的问题吗

@Next-Future-X
Copy link
Author

好的,我稍后试一下这段代码,测试设备在占用中

@Coder-TanJX
Copy link
Owner

WeChat53aabe6a1b96179285c607de4bb9eb53

@Next-Future-X
Copy link
Author

我尝试添加performBatchUpdates方法,在 iOS11、12、14系统运行,目前没有发现crash问题了。

@Coder-TanJX
Copy link
Owner

好的 谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants