【问题标题】:Make UIViewController the delegate of UICollectionView inside a UITableViewCell使 UIViewController 成为 UITableViewCell 内的 UICollectionView 的代表
【发布时间】:2018-05-28 13:48:40
【问题描述】:

我有一个 UIViewController,其中我有一个 UITableView,而在 tableViewCell 中我有一个 collectionView。如何让我的 ViewController 成为 CollectionView 的代表,以使自己与 MVC 架构保持一致?

【问题讨论】:

  • 到目前为止您尝试过什么?你能分享一些代码吗?
  • 你想对代理做什么?
  • 据我了解,我认为您希望在 collectionView 中执行操作时希望使用 Delegates 在 UIviewController 中发生更改?
  • @iOSGeek 是的。我想在我的视图控制器而不是我的 TableViewCell 中处理 CollectionView 单元格点击。
  • @BagusCahyono 我目前已将 UITableViewCell 作为 CollectionView 的代表,因为我的 collectionView 在 tableviewcell 内。虽然我知道这不是正确的方法,因此寻求更好的解决方案。我想在我的视图控制器中处理 collectionView 单元格点击。

标签: ios swift uitableview uicollectionview


【解决方案1】:

在您的cellForRowAt indexPath: IndexPath 中设置cell.yourCollectionView.delegate = yourViewController,并在 ViewController 中实现委托方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多