美文网首页
iOS 通知中心

iOS 通知中心

作者: chile | 来源:发表于2016-07-13 14:53 被阅读17次

What is NSNotificationCenter?

NSNotificationCenter是一种一对多的信息广播机制, 一个应用程序同时只能有一个NSNotificationCenter(通知中心)对象.
也就是说, 使用NSNotificationCenter必须要用到单例模式. 与此同时, 也用到了观察者模式.

Where to use NSNotificationCenter?

所有需要实现一对多的地方.

例如 : 点击一个按钮, 需要在多个不同页面有所响应.
(夜间模式)

How to use NSNotificationCenter?

使用的时候, 我习惯添加之后就去dealloc里写释放, 省的忙着写其他代码, 最后忘记释放, 给app搞crash了...

  1. 添加一个通知
    把通知的name写为常量字符串, 放在存放常量字符串的头文件中, 是我常用的做法.

    add
  2. dealloc方法里释放

    remove
  3. 在其他地方发送通知


    post

相关文章

  • IOS通知中心

    通知中心(NSnotificationCenter): 由发送者1或者多个发送者n 通过发送一个通知到通知中心,接...

  • iOS - 通知中心

    通知中心:NSNotificationCentereg:农村大喇叭发送广播 条件:在大喇叭广播之前要有村民(对象-...

  • iOS 通知中心

    不要随随便便就是用通知,不懂的话对性能影响挺大的.虽然用起来很方便. 下边是理论知识: 即使在适合使用通告的场合下...

  • iOS 通知中心

    What is NSNotificationCenter? NSNotificationCenter是一种一对多的...

  • iOS通知中心

    http://potter528.bj.bdysite.com 如果播放器播放完毕后通知中心通知对象,执行方法选择...

  • iOS通知中心

    有关的类 NSNotification NSNotificationCenter NSNotification N...

  • iOS 通知 与 通知中心

    iOS 通知中心:自己实现了一套消息机制,可以跨页面调用 类似Unity的SendMessage,是订阅、发布者模...

  • IOS 通知中心NotificationCenter

  • iOS通知中心-NSNotificationCenter

    NSNotification是iOS中一个调度消息通知的类,使用极为方便,但是劝各位还是慎用,当你日后修改工程的时...

  • iOS 通知中心(NSNotificationCenter)

    NSNotificationCenter 在这里第一步和第二步的顺序可以互换,一般楼主我喜欢先在需要发送消息的页面...

网友评论

      本文标题:iOS 通知中心

      本文链接:https://www.haomeiwen.com/subject/zejdjttx.html