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 . thanks in advance
推荐答案
你有两个选择
1) 实现集合视图委托 &视图控制器内的数据源.您可以在 tableview 的 cellForRowAt 方法中执行此操作,例如 cell.collectionview.datasource = self
1) Implement Collection view delegate & datasource inside view controller. You can do this in tableview's cellForRowAt method like cell.collectionview.datasource = self
2) 你可以创建委托/闭包来从 Collection View -> TableView Cell --> UIViewController
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
示例
由于您在理论上难以理解,这里是示例
As you have finding difficulties to understand theoretically here is example
假设在你的视图控制器中
suppose in your view controller
您有如下所示的 tableview 数据源
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
这篇关于UITableViewCell 里面的 UICollectionView 如何设置选择以将数据从当前视图传递到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!