1>在a页面中,创建观察者属性以及收到通知后的响应notiAction
//定义观察者属性
NSNotificationCenter.defaultCenter().addObserver(self, selector: “notiAction:”, name:“changeBackgroundColor”, object:nil)
//响应方法,传入初值
func notiAction(n:NSNotification){
let dic = n.userInfoas! [String:NSObject]
let bgColor = dic["backgroundColor"]as!UIColor
self.view.backgroundColor = bgColor
}
2>在b页面设置通知属性,发送发通知
func changeRed(){
//发送通知并传入数值
NSNotificationCenter.defaultCenter().postNotificationName("changeBackgroundColor", object: nil, userInfo: ["backgroundColor":UIColor.redColor()])
self.dismissViewControllerAnimated(true, completion: nil)
}