ios - UITableViewCell 中的 UICollectionView 如何设置选择以将数据从当前 View 传递到另一个 View

标签 ios swift uitableview uicollectionview uicollectionviewcell

我有一个 View Controller ,里面有一个 TableView ,在 TableView 中我实现了一个水平滚动的 Collection View ,数据显示正确但是当我点击传递一个 Collection View 单元格时我想转到另一个 View Controller 字符串到那个 View ,我该如何处理这个过程。 提前致谢

最佳答案

你有两个选择

1) 在 View Controller 中实现 Collection View 委托(delegate)和数据源。您可以在 tableview 的 cellForRowAt 方法中执行此操作,例如 cell.collectionview.datasource = self

2) 您可以创建委托(delegate)/闭包以从 Collection View -> TableView Cell --> UIViewController 传递数据

希望对您有帮助,如果您需要示例,请告诉我

示例

由于您在理论上难以理解,这里是示例

假设在你的 View Controller 中

你有如下 TableView 数据源

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier:"identifer", for: indexPath) as! YourTableViewCell

     // You have collection view inside tableview cell so 

       cell.yourCollectionViewObject.dataSource = self 
       cell.yourCollectionViewObject.delegate = self 

        return cell
    }

在您的 View Controller 中实现或移动数据源和委托(delegate),并推送或呈现您想要的 View Controller

关于ios - UITableViewCell 中的 UICollectionView 如何设置选择以将数据从当前 View 传递到另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54552625/

相关文章:

ios - Swift 错误声明委托(delegate)

ios - 如何执行激活编程约束

ios - 超视觉 iPhone 应用程序,如 UIView 或 UITableView 滚动

ios - 如何制作自定义高度的进度条?

ios - UICollectionReusableView 内部的标签始终为零

ios - 如何用swift连接mysql?

ios - Apple 是如何在 Apple Music 中制作专辑封面背后的模糊效果的?

ios - 检索存储在 childByAutoId() 引用中的特定 Firebase 数据 (Swift)

ios - UITableViewCell : Allowing Selective Deletion

ios - 让 UITableViewCell 显示没有红色减号的删除按钮