小编joh*_*ohn的帖子

Swift 协议委托返回 nil

protocol testDelegate: class {
    func open(channel: String, vc: UIViewController)
}

class test: UIViewController{

    weak var delegate: testDelegate?
}
override func viewDidLoad() {
        super.viewDidLoad()
        if self.delegate != nil {
        print("hello")
        self.delegate?.openGroupChannel(channel: channel!, vc: self)

}   
Run Code Online (Sandbox Code Playgroud)

那是课堂测试!测试类中的协议初始化也是如此

class calling:testDelegate{

override func viewDidLoad() {
        //blah blah       
    }   

func func open(channel: String, vc: UIViewController){
    print("calling")
}
Run Code Online (Sandbox Code Playgroud)

这是调用类。

我想在调用类中调用 open func 但它根本不调用,甚至测试类中的 print("hello") 也没有调用它,它保持返回 nil 因此也不会调用调用函数。

iphone ios swift3

0
推荐指数
1
解决办法
3445
查看次数

标签 统计

ios ×1

iphone ×1

swift3 ×1