【发布时间】:2015-09-01 12:54:12
【问题描述】:
我想使用委托使我的单元格(来自 UICollectionView)与我的 ViewController 进行通信。
在我的 Cell.swift 文件中,我声明所需的协议是这样的(在 Cell 类之外):
protocol CellDelegate: class {
func someMethod(param1: String?, param2 param2: Bool)
}
在同一个文件中,我将委托声明如下:
class Cell: UICollectionViewCell {
weak var delegate: CellDelegate?
// ... some code ...
@IBAction func someAction(sender: AnyObject) {
delegate?.someMethod(param1, param2: true)
}
}
现在在我的 ViewController 中,我正在实现 someMethod:
extension ViewController: CellDelegate {
func someMethod(param1: String?, param2 param2: Bool) {
// ... some code ...
}
}
问题:我无法将协议与其实现联系起来,协议中的cmd + click 无处可去。在我的@IBAction 中,someMethod 没有崩溃,但它什么也不做。
我看到this topic关于这个主题,但我不明白在哪里实施第6步。
你能帮帮我吗?
感谢您的宝贵时间。
【问题讨论】:
标签: ios iphone swift delegates protocols