【发布时间】:2019-01-14 08:04:51
【问题描述】:
我正在尝试检测UITableViewCell 中的按钮点击,该UICollectionViewCell 中的按钮。
UICollectionView 的委托和数据源是我的ViewController。每个UICollectionViewCell 中都有一个UITableView。而UITableViewCell 的委托和数据源是UICollectionViewCell。
我需要检测ViewController 中的按钮点击。
视图控制器
@IBOutlet collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
}
UICollectionView
@IBOutlet tableView: UITableView!
override func awakeFromNib() {
super.awakeFromNib()
tableView.delegate = self
tableView.dataSource = self
}
UITableViewCell
@IBAction func buttonTapped(_ sender: CustomButton) {
// Detect Button Tap in ViewController
}
【问题讨论】:
-
添加一些额外的代码
-
在集合视图单元格类中调用 tableView 的委托和数据源方法
-
好吧,如果它是单元格中唯一的按钮,您可以依赖表格视图委托 didSelect 或者您可以创建委托模式或使用闭包来通知控制器。
标签: ios swift uitableview uicollectionview