[英]UICollectionView inside UITableViewCell how to set the selection to pass data from the current view to another one
I have a view controller with a tableview inside it , in the table view i implemented a collection view with horizontal scrolling, the data appears correctly but i want to go to another view controller when i click on the collection view cell passing a string to that view , how can i handle this process . 我有一个内部带有tableview的视图控制器,在表视图中,我实现了带有水平滚动的集合视图,数据正确显示,但是当我单击传递字符串的集合视图单元格时,我想转到另一个视图控制器看来,我该如何处理这个过程。 thanks in advance
提前致谢
You have two choice 你有两个选择
1) Implement Collection view delegate & datasource inside view controller. 1)在视图控制器内部实现Collection视图委托和数据源。 You can do this in tableview's cellForRowAt method like
cell.collectionview.datasource = self
您可以在tableview的cellForRowAt方法中执行此操作,例如
cell.collectionview.datasource = self
2) You can create delegate / closure to pass data from Collection View -> TableView Cell --> UIViewController 2)您可以创建委托/闭包以从Collection View-> TableView Cell-> UIViewController传递数据
Hope it is helpful And let me know if you need example 希望对您有所帮助,并让我知道您是否需要示例
EXAMPLE 例
As you have finding difficulties to understand theoretically here is example 由于您在理论上难以理解,因此这里是示例
suppose in your view controller 假设在您的视图控制器中
You have tableview datasource like below 您有如下的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
}
Implement or Move the datasource & Delegate in Your view Controller and push or present view controller you want to 在您的View Controller中实现或移动数据源和委托,并推送或呈现您想要的View Controller
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.