//通知的使用

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

相关文章:

  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案