//通知的使用
1.發(fā)通知。(以這條通知為例,通知名字:nickNameNotification 通知參數(shù):title)
NSNotificationCenter.defaultCenter().postNotificationName("nickNameNotification", object: title);
此處的 title 是要傳的參數(shù)2.在要監(jiān)聽這則通知的viewDidload方法里面添加觀察者,以便監(jiān)聽這則通知
NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateNickName:", name: "nickNameNotification", object: nil);3.實現(xiàn)2中的selector,監(jiān)聽到通知調(diào)用的方法
func updateNickName(title:NSNotification){ var str = title.object as String; self.titleLable.text = str;}新聞熱點
疑難解答