协议方法未从其他类调用

时间:2019-05-18 19:18:46

标签: ios swift protocols

我想从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时都会调用。

0 个答案:

没有答案