【问题标题】:My project show before tableViewCell display label finished, CollectionViewCell display inner label in swit3?我的项目在tableViewCell显示标签完成之前显示,CollectionViewCell在swit3中显示内部标签?
【发布时间】:2017-11-26 11:51:06
【问题描述】:

如何控制在TableViewCell标签显示前,我的CollectionViewCell标签显示? 我的 CollectionViewCell 在 TableViewCell 中。

  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 


         let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CollectionViewCell

                let list = sections[(indexPath as NSIndexPath).row]

                DispatchQueue.main.async {

                    cell.categoryTitle.text = list.package_name
                    cell.mainAssociatedURL.text = list.package_url
                    cell.collectionView.tag = indexPath.row
                    cell.collectionView.reloadData()

                }

         return cell

    }
}

我的 CollectionViewCell 在这里,

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

 let list = sections[indexPath.row].packageTable[indexPath.row]

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "videoCell", for: indexPath) as! CollecitonViewCell



        AsyncImageLoader.sharedLoader.imageForUrl(urlString: list.poster_url) { (image, url) -> () in
            DispatchQueue.main.async(){

                cell.movieTitle.text = list.name
                if(url == StringResource().posterURL){
                    cell.imageView.image = UIImage(named: "mmcast_cover")
                }else{
                    cell.imageView.image = image
                }
            }
        }

    return cell

}

我想先显示 TableViewCell 标签显示,然后再显示 CollectionViewCell 标签和图像。

【问题讨论】:

  • 不清楚,可以的话请多解释
  • @UsamaSadiq 我编辑了,希望你能理解。

标签: ios xcode swift3 uicollectionviewcell tableviewcell


【解决方案1】:

您需要在 tableviewcell 中分配 collectionView 的委托。

在 ViewDidLoad 中

cell.collectionView.delegate = nil
cell.collectionView.datasource = nil

委托变更

  let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CollectionViewCell

                    let list = sections[(indexPath as NSIndexPath).row]

                    DispatchQueue.main.async {

                        cell.categoryTitle.text = list.package_name
                        cell.mainAssociatedURL.text = list.package_url
                        cell.collectionView.tag = indexPath.row
                        cell.collectionView.delegate = self
                        cell.collectionView.datasource = self
                        cell.collectionView.reloadData()

                    }

             return cell

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    相关资源
    最近更新 更多