我在 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/