我有一个 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/