嗨,我在使用自定义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")
}
答案 0 :(得分:2)
在您的function shutdown() {
if [[ "$?" != "0" ]]
then
# Only run if previous command was not successful
npm run poststart
fi
}
中,您是否像下面那样分配了单元格的代表?
npmbash run dev
答案 1 :(得分:0)
制作单元时,您可能没有将控制器设置为委托对象。
//在您的控制器中
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VideoCell", for: indexPath) as! SearchVideoCell
cell.delegate = self