7.iOS Notification
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的更多相关文章
- iOS - Notification 通知
1.Notification 通知中心实际上是在程序内部提供了消息广播的一种机制,它允许我们在低程度耦合的情况下,满足控制器与一个任意的对象进行通信的目的.每一个 iOS 程序(即每一个进程)都有一个 ...
- iOS Notification – 远程通知
本文讲解iOS的远程通知的基本使用,主要包括远程通知的类型,处理远程通知的场景,以及远程通知相关证书的配置等等. 一.APNs简介 APNs是苹果公司提供的远程通知的服务器,当App处于后台或者没有运 ...
- ios notification
apps can use local or push notifications to let people know when interesting things happen, such as: ...
- iOS Notification 的使用
Notification post notification,notification,notification,notification,notification,n otification ,no ...
- IOS Notification 通知中心
1. 通知中心概述 通知中心实际上是在程序内部提供了消息广播的一种机制.通知中心不能在进程间进行通信.实际上就是一个二传手,把接收到的消息,根据内部的一个消息转发表,来将消息转发给需要的对象. ...
- Android Broadcast 和 iOS Notification
感觉以上2个机能有许多相似之处,作个记录,待研究!
- iOS.Notification.Bar.Color
Reference: http://apple.stackexchange.com/questions/44246/what-determines-the-special-color-of-the-s ...
- 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 ...
- iOS.OpenSource.AllInOne
Open Source Project for iOS 所有和iOS相关的Open Source Project的汇总. 功能点 开源项目 iOS Gallery RMGallery https: ...
随机推荐
- 页内多个input全选不干扰且只用一段代码。
//html内容 <body> <div id="d1"> <input type="checkbox" class=" ...
- Javascript字节转换
//文件大小转换 function bytesToSize(bytes) { if (bytes === 0) return '0 B'; var k = 1024; sizes = ['B', 'K ...
- iOS代码规范
一.文档结构管理 1.建立Libraries文件夹,所有第三方库放入其中. 2.建立Utilities文件夹,自已封装的类放入其中. 3.建立Constants.h头文件,所有的常量定义于其中.Con ...
- 了解PHP中的register_shutdown_funcion
(PHP 4, PHP 5, PHP 7) register_shutdown_function - Register a function for execution on shutdown 执行P ...
- 论php数组合并
注:尽量不要在循环中操作数据库. 1.两个一维数组合并成一个一维数组 $a = array('morning','afternoon','night'); $b = array('breakfast' ...
- Netty源码分析之服务端启动过程
一.首先来看一段服务端的示例代码: public class NettyTestServer { public void bind(int port) throws Exception{ EventL ...
- ip地址库 新浪,淘宝
原文连接地址:http://www.9958.pw/post/city_ip function getAddressFromIp($ip){ $urlTaobao = 'http://ip.taoba ...
- 把域名绑定到某个项目,以nginx服务器为例
一:登陆域名服务器平台,把域名解析到项目对应的IP上面. 二:配置nginx服务器 1./etc/nginx/conf.d/ 在服务器该目录下,添加.conf文件,如命名为:www.demo.com. ...
- linux查看端口及端口详解
今天现场查看了TCP端口的占用情况,如下图 红色部分是IP,现场那边问我是不是我的程序占用了tcp的链接,,我远程登陆现场查看了一下,这种类型的tcp链接占用了400多个,,后边查了一下资料,说E ...
- shell脚本学习第一课
shell是一种程序设计语言,是访问操作系统内核的服务. Linux的shell种类常见的有: Bourne Shell(/usr/bin/sh或/bin/sh) Bourne Again Shell ...