gpt4 book ai didi

ios - 在 UICollectionView didSelectItemAt 上调用主线程

转载 作者:行者123 更新时间:2023-11-29 00:34:55 25 4
gpt4 key购买 nike

我使用的是 UICollectionView,当用户点击一个单元格时,一个特定的进程就会运行。由于此过程可能需要几秒钟,因此我想在此过程即将开始时立即向用户显示一个带有一些处理消息的 View 。

大致思路如下:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

DispatchQueue.main.async {
self.someView.isHidden = false
print("showing processing message is about to start")
}

// some process runs here which may take a few seconds to finish

DispatchQueue.main.async {
self.someView.isHidden = true
print("hidding processing message")
}

}

由于某些我不知道的原因,那些对主线程的调用是在 didSelectItemAt 完全完成之后执行的,因此处理消息几乎在它出现的同时消失了。

有人知道我在这里缺少什么吗?

谢谢:)

最佳答案

由于 someView 正在主线程上调用,因此根据您输入的代码片段,您在问题中描述的内容似乎很正常。

如果您希望在进程完成时隐藏 someView,最好在您打算运行的进程的完成关闭中隐藏 someViewsomeView 没有被隐藏。

关于ios - 在 UICollectionView didSelectItemAt 上调用主线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40853613/

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