Swift通知傳值
阿新 • • 發佈:2018-12-17
通知方
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() }