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