UICollectionView inside UITableViewCell how to set the selection to pass data from the current view to another one

情到浓时终转凉″ 提交于 2021-02-11 06:16:12

问题


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 . thanks in advance


回答1:


You have two choice

1) Implement Collection view delegate & datasource inside view controller. You can do this in tableview's cellForRowAt method like cell.collectionview.datasource = self

2) You can create delegate / closure to pass data from 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

 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



来源:https://stackoverflow.com/questions/54552625/uicollectionview-inside-uitableviewcell-how-to-set-the-selection-to-pass-data-fr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!