简体   繁体   English

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

[英]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.

相关问题 如何在uitableviewcell内设置uicollectionview的高度? - How to set the height of a uicollectionview inside an uitableviewcell? 在UITableViewCell内为UICollectionView设置插座 - Set an outlet for a UICollectionView inside a UITableViewCell 如何将数据 UItableViewCell 传递给另一个 viewController 和 UItableViewCell? - How to pass data UItableViewCell to Another viewController and UItableViewCell? 如何在IOS中将数据从一个视图传递到另一个视图控制器? - How to pass data from one view to another view controller in IOS? 如何通过parentviewController将数据从一个视图传递到另一个视图 - how to pass data from one view to another view through parentviewcontroller 如何使用委托将数据从一个视图控制器传递到另一个视图控制器? - how to use delegate to pass data to from one View Controller to another? 将数据从一个视图传递到另一个视图 - Pass data from one view to another 如何从uitableviewcell选择中设置子视图的标题 - how to set the title of a subview from a uitableviewcell selection 通过其中的 Button 从 UITableViewCell 传递数据 - Pass data from UITableViewCell by Button inside it 从UICollectionView中选择后,使用核心数据填充详细信息视图 - Use core data to populate detail view after selection from UICollectionView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM