Swift通知传值

如果您在阅读我的文章时有疑问 , 请点击这里
通知方

NotificationCenter.default.post(name: NSNotification.Name(rawValue:"s"), object:nil, userInfo:["one":languageField!.text! , "two":EnglishField!.text! , "three":mathematicsField!.text!])

接受方

NotificationCenter.default.addObserver(self, selector: #selector(upDataChange(notif:)), name: NSNotification.Name(rawValue: "s"), object:nil )

@objc func upDataChange(notif: NSNotification){
        self.label1 = (notif.userInfo!["one"] as? String)!
        self.label2 = (notif.userInfo!["two"] as? String)!
        self.label3 = (notif.userInfo!["three"] as? String)!
        nameCell.append(self.label1 as AnyObject)
        nameCell.append(self.label2 as AnyObject)
        nameCell.append(self.label3 as AnyObject)
        self.tableView .reloadData()
    }

你可能感兴趣的:(Swift通知传值)