1. 通知中心认识

通知中心实际上是在程序内部提供了消息广播的一种机制。通知中心不能在进程间进行通信,它只能进行程序内部通信,不能跨应用程序进程通信。通知中心,当通知中心接受到消息后会根据设置,根据内部的一个消息转发表,将消息转发给订阅者。通知中心是基于观察者模式的,它允许注册、删除观察者。通知中心与代理模式类似,都可以实现多个对象间通信,通知中心可以将一个通知发送给多个监听者,而代理模式每个对象只能添加一个代理。但无论是那种模式,都是一种低耦合的设计,实现对象间的通信。

2. 通知中心的使用

第一步:注册通知中心(就是谁去接受广播)

// 参数1 谁去就收广播的消息

// 参数2 接收到广播后要执行的操作

// 参数3 接受哪个广播(也是就广播的标识)

[[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector (runSel:) name:@"MCJ" object:nil];

第二步:发送广播 这个方法一般在其他对像有什么变数时 在其他对象里写

// 参数1 给广播添加标识(在接受广播的地方,可以通过这个值区分不同的广播)

// 参数 2 需要传递的参数 没有的话可以传nil

[NSNotificationCenter defaultCenter] postNotificationName:@" MCJ" object:array];

第三步: 实现接收到广播后要执行的方法,如果有参数需要加上(NSNotification *)sender

sender.object 就是我们传过来的参数

- (void)runSel: (NSNotification *)sender {

    NSArray *array =
sender.object;
    _nameLable.text = array[0];

    _passwordLabel.text =
array[1];
    self.view.backgroundColor
= [UIColor redColor];
}

第四步:移除通知(有两种方式)

- (void)dealloc {

// 移除指定的通知中⼼心

    [[NSNotificationCenter
defaultCenter]
removeObserver:self
name:@"MCJ" object:nil];

// 移除所有的通知中⼼心

    [[NSNotificationCenter
defaultCenter]
removeObserver:self];
}

7.iOS Notification的更多相关文章

  1. iOS - Notification 通知

    1.Notification 通知中心实际上是在程序内部提供了消息广播的一种机制,它允许我们在低程度耦合的情况下,满足控制器与一个任意的对象进行通信的目的.每一个 iOS 程序(即每一个进程)都有一个 ...

  2. iOS Notification – 远程通知

    本文讲解iOS的远程通知的基本使用,主要包括远程通知的类型,处理远程通知的场景,以及远程通知相关证书的配置等等. 一.APNs简介 APNs是苹果公司提供的远程通知的服务器,当App处于后台或者没有运 ...

  3. ios notification

    apps can use local or push notifications to let people know when interesting things happen, such as: ...

  4. iOS Notification 的使用

    Notification post notification,notification,notification,notification,notification,n otification ,no ...

  5. IOS Notification 通知中心

    1.     通知中心概述 通知中心实际上是在程序内部提供了消息广播的一种机制.通知中心不能在进程间进行通信.实际上就是一个二传手,把接收到的消息,根据内部的一个消息转发表,来将消息转发给需要的对象. ...

  6. Android Broadcast 和 iOS Notification

    感觉以上2个机能有许多相似之处,作个记录,待研究!

  7. iOS.Notification.Bar.Color

    Reference: http://apple.stackexchange.com/questions/44246/what-determines-the-special-color-of-the-s ...

  8. Send Push Notifications to iOS Devices using Xcode 8 and Swift 3, APNs Auth Key

    Send Push Notifications to iOS Devices using Xcode 8 and Swift 3 OCT 6, 2016 Push notifications are ...

  9. iOS.OpenSource.AllInOne

    Open Source Project for iOS 所有和iOS相关的Open Source Project的汇总. 功能点 开源项目   iOS Gallery RMGallery https: ...

随机推荐

  1. cocos2dx3.0的CCCallFunc、CCCallFuncN

    来源: http://blog.csdn.net/crayondeng/article/details/18767407 二.在cocos2d-x中,还有一个地方是需要大量使用到回调函数的,这就是回调 ...

  2. (转)git常见错误

    如果输入$ Git remote add origin git@github.com:djqiang(github帐号名)/gitdemo(项目名).git 提示出错信息:fatal: remote ...

  3. Javascript格式化json返回的时间(/Date(1482747413000)/)

    //时间处理,类似/Date(1482747413000)/的形式,得到xxx年xx月xx日 11:11:11 function ChangeDateFormat(jsondate) { jsonda ...

  4. float 对整形的取余运算

    取余是针对整形的,但是有时候一些特殊需求,我们需要 float 型对整形取下余数.比如,将角度化到 0- 360 范围内. 今天看到 lua 的实现方式: a % b == a - math.floo ...

  5. HTTP Request Method共计15种

    更多信息可参考http://tools.jb51.net/table/http_request_method

  6. easyUI和bootstrap的混搭

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  7. HTTP 基础知识

    HTTP是一种协议.HTTP使用流程,一般情况下, 第一:由HTTP客户端发出请求,创建端口. 第二:HTTP服务器在端口监听客户端的请求. 第三:一旦收到请求,HTTP服务器向客户端返回状态和内容. ...

  8. 报错:emulator: WARNING: ./android/metrics/metrics_reporter_toolbar.cpp:167: Can't upload usage metrics: Error

  9. Vue.js 整理笔记

    以前我们用Jquery进行dom的操作,虽然熟悉后开发效率很高,但是如果多个控件的相互操作多的情况下,还是会乱.相比之下,Vue的使用更加清晰,通过虚拟dom将数据绑定,而且组件化和路由的帮助下,让整 ...

  10. 2016百度之星 资格赛ABCDE

    看题:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=690 交题:http://acm.hdu.edu.cn/search.php ...