1. 程式人生 > >Swift通知傳值

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()
    }