【发布时间】:2018-11-08 03:32:12
【问题描述】:
您好,我在使用自定义 delegate 传递数据时遇到问题,请帮助大家这是我的代码
protocol VideoCellDelegate {
func didSaveFavorite(for cell: SearchVideoCell)
}
我把我的delegate 放在SearchVideoCell 里面
class SearchVideoCell: UICollectionViewCell {
var delegate: VideoCellDelegate?
这是我在SearchVideoCell中的函数
@objc func handleFavorite() {
print("Handling favorite")
delegate?.didSaveFavorite(for: self)
}
比我尝试传入的SearchVideoController
class SearchVideoController: UICollectionViewController, UICollectionViewDelegateFlowLayout, VideoCellDelegate
比我打电话给delegate 但它不起作用,它只打印Handling Favorite 而不是saving video to favorite
func didSaveFavorite(for cell: SearchVideoCell) {
print("saving video to favorite")
}
【问题讨论】:
标签: swift delegates swift-protocols