问题
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