广播方式传值

广播传:

@IBAction func next(sender: AnyObject){
let nc=NSNotificationCenter.defaultCenter()
var a=[String]()
var b=[String]()
a.append("phone_num"); a.append("phone_num1");
b.append(tx_Remark1.text); b.append(tx_Remark2.text);
let dic=NSDictionary(objects: b, forKeys: a)
let register2ct = register2CT(nibName: "register2",bundle: nil)
self.presentViewController(register2ct, animated: false, completion: {
nc.postNotificationName("phone_num", object: dic)
})
}

广播取:

import Foundation
import UIKit

class register2CT:UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
let nc=NSNotificationCenter.defaultCenter()
nc.addObserver(self, selector: "handler:", name: "phone_num", object: nil)
}
@IBOutlet var quxiao:UIButton!
var phonenum: String=" "

@IBAction func OnBackup(sender:AnyObject){
self.dismissViewControllerAnimated(true, completion:{})
}

func handler(ntf:NSNotification){
let dic = ntf.object as! NSDictionary
phonenum = dic["phone_num"] as! String
print(phonenum)
}

}

原文地址:https://www.cnblogs.com/to-creat/p/5375420.html