【发布时间】:2021-06-24 18:04:52
【问题描述】:
我有一个在 TableView Cell 中有几个项目的 collectionView,每个项目都应该推送到下一个 ViewController,问题是我不能使用 collectionView 和 tableView Cell 中的 push() 函数,所以我创建了一个当我用于单击 collectionView 项目时,该协议会从 Main ViewController 中触发推送功能。
这是协议:
protocol PushToAgents {
func pushToAgents()
}
这是我从协议中实现功能的主要 Vc:
class MoreViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, PushToAgents, PushToBank, PushToCredit, PushToNewInserate {
//MARK: - Protocol Functions
func pushToAgents() {
present(AgentsVC(), animated: true, completion: nil)
}
}
这是 CollectionView:
class FeatureCollectionCell: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate {
var agentsDelegate: PushToAgents?
var bankDelegate: PushToBank?
var creditDelegate: PushToCredit?
var newInserateDelegate: PushToNewInserate?
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if indexPath.row == 0 {
agentsDelegate?.pushToAgents()
}
if indexPath.row == 1 {
self.bankDelegate?.pushToBank()
}
if indexPath.row == 2 {
self.creditDelegate?.pushToCredit()
}
if indexPath.row == 3 {
self.newInserateDelegate?.pushToNewInserate()
}
}
问题是它什么也没做,谁能帮忙告诉我问题出在哪里?
【问题讨论】:
-
您是否初始化了委托的属性?
-
FeatureCollectionCell 既是表格单元格又是集合视图委托和数据源?
-
@YuriiPetrov 你是什么意思?
-
@jnpdx 是的,它是一个带有 CollectionView 的 tableView 单元格!
-
请添加表格视图的cellForRow方法
标签: swift uitableview uicollectionview