我想从FoldingClass调用方法,该方法扩展了UITableViewCell动作,从而调用B类中的方法
因此,我实现了协议以基于用户按钮操作进行委派。
protocol ModelDelegate: class {
func didReceiveData(_ data: String)
}
class Folding: FoldingCell {
weak var delegate: ModelDelegate?
// MARK: - Remove Button Actions
extension Folding {
func didReceiveData(_ data: String) {
}
func downloadData() {
let data = "Network request information."
delegate?.didReceiveData(data)
}
@IBAction func buttonHandler(_ sender: AnyObject) {
print("button Handler",sender.tag!)
self.delegate?.didReceiveData("Self")
}
}
B级
class ClassB: NSObject {
let model = Folding()
override init() {
super.init()
model.delegate = self
model.downloadData()
}
}
extension ClassB: ModelDelegate {
func didReceiveData(_ data: String) {
print(data)
}
}
期待按钮Action didReceividedData每次我单击按钮Action时都会调用。