首页 > 解决方案 > UICollectionViewCell 未在 UITabBarController 选项卡更改后立即加载

问题描述

好的,所以我有部分代码在其中更改UITabBarController's选项卡(更改为 a UICollectionView),然后在它之后显示一个弹出窗口,其中包含特定单元格的 sourceView 和 sourceRect UICollectionView

我遇到的问题是,当我事先浏览该选项卡时,一切正常。

但是,一旦我尝试不选择该选项卡,它就会由于未加载单元格而崩溃。这听起来很公平,但我该如何解决呢?

做一些 0.1 秒的调度延迟似乎是一个可疑的解决方案..

   tabBarController.selectedViewController = vc 
      if let cell = vc.collectionView?.cellForItem(at: IndexPath(item: index, section: 0)) {
        alertVC.popoverPresentationController?.sourceView = cell
        alertVC.popoverPresentationController?.sourceRect = cell.bounds
      } 
   // if statement gets ignored as cv is not yet loaded as it seems

标签: iosswiftuicollectionviewuitabbarcontrolleruicollectionviewcell

解决方案


推荐阅读