swift-通知的基本使用

时间:2015-11-07 21:39:40   收藏:0   阅读:215

//通知的使用

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;
}

 

原文:http://www.cnblogs.com/motoyang/p/4946028.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!