swift - 如何在 TableView 单元格上的 Collection View 数据源中调用多个CollectionView

标签 swift xcode uicollectionview tableview uicollectionviewcell

我在 TableView 单元格中有 2 个 Collection View ,每个 Collection View 在自己的 TableView 单元格中有 Outlet。我如何在 View Controller 的 cellForItemAt 方法中调用和使用这两个 Collection View 。

if (collectionView == self.amazing_Collection) // doesnt work

这是 View Controller 中的 TableView 方法

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

    let section = indexPath.section  
    if section == 0 {
         let cell0  = tableView.dequeueReusableCell(withIdentifier: "searchCell", for: indexPath) as! searchCell
         return cell0

          }else if section == 1 {
            let cell1  = tableView.dequeueReusableCell(withIdentifier: "slideCell", for: indexPath) as! slideCell

返回单元格0

这是填充图像和标签的 Collection View 方法

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

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: “amazingCollecionCell”,用于:indexPath)作为!惊人的细胞集合 ////这是正确工作的 返回单元格

return cell 

        //here iwant to say if this collection view execute under lines  
        let cell_Just_Here = collectionView.dequeueReusableCell(withReuseIdentifier: "justhereproductscell", for: indexPath) as! JustHereProductsCell
        //lable fill



        return cell_Just_Here
    }
}

最佳答案

当调用tableview的数据源方法时,将collection view的tag值设置为indexPath.row(单元格的索引路径)。通过在 Collection View 的数据源方法中,您将能够使用标签值识别 Collection View 并相应地设置单元格。

希望这有帮助。

关于swift - 如何在 TableView 单元格上的 Collection View 数据源中调用多个CollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56505592/

相关文章:

ios - 自构建预编译头以来文件已被修改

ios - 在方向上更改 UICollectionViewCell 布局

swift - 嵌套类中名为 `Type` 的枚举失败

ios - swift 警告 : Application delegate received call to -application:performFetchWithCompletionHandler: but the completion handler was never called

ios - 如何使用平移手势识别器旋转 SCNSphere

ios - 启动屏幕问题

ios - 不调用索引路径行的空 TableView 单元格

swift - 在新的 Firebase 和 Swift 中创建用户

ios - UICollectionView 水平滚动,数据从左向右流动

swift - 自动布局 ImageView 高度 anchor 在 Collection View 中发生冲突并且无法正常工作