【问题标题】:Delegate UICollectionView in UITableViewCell在 UITableViewCell 中委托 UICollectionView
【发布时间】:2023-03-21 08:21:01
【问题描述】:

我无法决定谁应该是 UICollectionView 的代表,它是 UITableViewCell 的子视图。 UITableView 将其控制器作为故事板中的委托。 UITableViewCell(带有 UICollectionView)有自己的 xib。 但是谁应该是他的 UITableViewCell 中的 UICollectionView 的代表呢?

我尝试在 UITableViewCell 上链接 UICollectionView 的委托,但没有成功。

【问题讨论】:

  • 你的意思是“我试过 UITableViewCell,但没用。”。用您迄今为止尝试过的内容编辑您的问题?如果有帮助,请也检查此链接:ashfurrow.com/blog/…

标签: ios uitableview uicollectionview uikit


【解决方案1】:

一般情况:

任何需要使用委托回调的东西......都应该是委托,任何持有数据源的对象都需要成为数据源。 通常 那是一个 UIViewController。

具体来说:

您的情况略有不同。你的层次结构是这样的:

ViewController >> TableView & TableViewCell >> CollectionView.

你可以做的是让你的 viewController 成为 collectionView 的代表。但不建议这样做,因为您跳过了一层层次结构。我建议您将 tableViewCell 设置为 collectionView 的代表,然后将控制器再次设置为 tableViewCell 的代表,尽管这将是一些自定义代表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    相关资源
    最近更新 更多