iOS通知的实现
来源:互联网 发布:ai人工智能教程 编辑:程序博客网 时间:2024/05/22 06:08
iOS的通知就好比c语言中的函数回调。设置好触发事件和相应事件,这就是一个很好用的方式,是多个控制器中常用的一种方式。
使用方法:首先设置相应事件
1、在要响应的控制器中注册监听者
//注册监听者。
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(goChange:)name:@"ChangeColor"object:nil]; //收到通知后,执行方法:goChange: name关键字是区分监听使用的,意思就是可以有多个响应事件,每个响应事件根据name关键字对应一个触发事件
2、在要触发事件的控制器添加触发事件
UIColor *color = [UIColorcolorWithRed:red green:greenblue:blue alpha:alpha]; //产生随机颜色
NSDictionary *dic = [NSDictionarydictionaryWithObject:color forKey:@"color"];
[[NSNotificationCenterdefaultCenter]postNotificationName:@"ChangeColor"object:selfuserInfo:dic];
响应函数样式:
-(void)goChange:(NSNotification *)notification
{
//拿到通知内容。
NSDictionary *dic = [notification userInfo];
UIColor *color = [dic objectForKey:@"color"];
self.view.backgroundColor = color;
}
- iOS通知的实现
- iOS 推送通知的实现
- iOS本地通知的实现
- iOS远程通知的实现
- iOS 本地通知的实现
- iOS本地通知的实现
- iOS 本地通知的实现
- IOS推送通知的实现步骤
- IOS推送通知的实现步骤
- IOS推送通知的实现步骤
- IOS推送通知的实现步骤
- iOS通知中心的简单实现-YRSignal
- iOS远程通知的实现机制
- iOS关于系统原生通知的实现
- 简单实现iOS通知中心的功能
- ios通知的一个简单实现
- iOS实现本地通知
- iOS推送通知实现
- Ubuntu登陆密码忘记后找回方式
- startActivityForResult使用步骤分解
- 从零开始机器学习实战2-Matplotlib绘图
- 《ARM与Linux些许问题》第四章:ARM平台系统调用原理分析
- intellij 中设置内存大小
- iOS通知的实现
- replaceAll和replace的替换差别
- scrapy安装
- 【REST】REST、RESTFUL的理解以及SpringMVC实现Restful编程
- 如何调试nutch
- 常见的C#窗体间的传值(二)
- CCS5.5.0的include路径和lib路径的配置
- matlab学习笔记(二)---三维图形的绘制
- MyEclipse中xml的区别xml(advanced Templates)、xml(Basic Templates)、xml schema