您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页iOS系统复习(一) 通知

iOS系统复习(一) 通知

来源:二三娱乐

一, NSNotification (通知)

  • 通知: 是一个对象能给其他任意数量的对象广播消息的一种方式,对象之间没有耦合关系
  • NSNotification(通知),封装了要广播的信息(包括用做标签’名字’,需要发送的任意类型的’对象’,一个存放其他信息的字典)
  • NSNotificationCenter(通知中心),管理注册接收消息对象,广播消息; NSNotificationCenter是一个单例可以通过+defaultCenter方法获取,
  • Observer(观察者),需要监听通知的对象,即广播的信息的接受者
    注意:observer在结束监听时需要在通知中心注销
  • 常用方法:
    1 创建通知
    notificationWithName:object: notificationWithName:object:userInfo:.
    2 通过通知中心发送通知
    postNotificationName:object: postNotificationName:object:userInfo:
    3 添加一个监听者
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aWindowBecameMain:) name:NSWindowDidBecomeMainNotification object:nil];
    4 移除监听者
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@”” object:nil];

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务