ios通知使用 书上案例 简单易懂
/* The notification name */
const NSString *ResultOfAppendingTwoStringsNotification =
@"ResultOfAppendingTwoStringsNotification"; /* Keys inside the dictionary that our notification sends */
const NSString
*ResultOfAppendingTwoStringsFirstStringInfoKey = @"firstString";
const NSString
*ResultOfAppendingTwoStringsSecondStringInfoKey = @"secondString";
const NSString
*ResultOfAppendingTwoStringsResultStringInfoKey = @"resultString";
//发送通知方法
- (void) broadcastNotification{
NSString *firstName = @"Anthony";
NSString *lastName = @"Robbins";
NSString *fullName = [firstName stringByAppendingString:lastName];
NSArray *objects = [[NSArray alloc] initWithObjects:
firstName,
lastName,
fullName,
nil];
NSArray *keys = [[NSArray alloc] initWithObjects: ResultOfAppendingTwoStringsFirstStringInfoKey, ResultOfAppendingTwoStringsSecondStringInfoKey, ResultOfAppendingTwoStringsResultStringInfoKey,
nil];
NSDictionary *userInfo = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];
NSNotification *notificationObject =
[NSNotification notificationWithName:(NSString *)ResultOfAppendingTwoStringsNotification object:self
userInfo:userInfo];
[[NSNotificationCenter defaultCenter] postNotification:notificationObject];
}
//监听通知调用方法
- (void) appendingIsFinished:(NSNotification *)paramNotification
{
NSLog(@"Notification is received.");
NSLog(@"Notification Object = %@",[paramNotification object]);
NSLog(@"Notification User-Info Dict = %@", [paramNotification userInfo]);
}
- (void)viewDidLoad
{
//监听通知
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(appendingIsFinished:)
name:(NSString *)ResultOfAppendingTwoStringsNotification object:self];
//发送通知
[self broadcastNotification];
}
ios通知使用 书上案例 简单易懂的更多相关文章
- 做小图标还用sprite图?你out了!史上最简单易懂iconfont使用教程
1.什么是iconfont? 说白了就是用图标制作而成的一套字体文件,本质是一个字体文件(扩展名是ttf\woff\svg的文件).它是用来制作网页常用小图标的一种方法.以下是天猫首页使用iconfo ...
- IOS xib在tableview上的简单应用(通过xib自定义cell)
UITableView是一种常用的UI控件,在实际开发中,由于原生api的局限,自定义UITableViewCell十分重要,自定义cell可以通过代码,也可以通过xib. 这篇随笔介绍的是通过xib ...
- 史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS。
重要的话 开头说,not for the RecyclerView or ListView, for the Any ViewGroup. 本控件不依赖任何父布局,不是针对 RecyclerView. ...
- IOS开发中UIBarButtonItem上按钮切换或隐藏实现案例
IOS开发中UIBarButtonItem上按钮切换或隐藏案例实现案例是本文要介绍的内容,这个代码例子的背景是:导航条右侧有个 edit button,左侧是 back button 和 add bu ...
- Session小案例-----简单购物车的使用
Session小案例-----简单购物车的使用 同上篇一样,这里的处理请求和页面显示相同用的都是servlet. 功能实现例如以下: 1,显示站点的全部商品 2.用户点击购买后,可以记住用户选择的商品 ...
- iOS通知的整理笔记
iOS通知用于高耦合界面的传值确实方便快捷. 需要实现模态弹出的视图控制器上,有一个视图控制器可以导航.这必定要将这个视图控制器的导航视图控制器naVC.view添加到模态弹出的视图控制器presen ...
- 李洪强iOS经典面试题上
李洪强iOS经典面试题上 1. 风格纠错题 修改完的代码: 修改方法有很多种,现给出一种做示例: // .h文件 // http://weibo.com/luohanchenyilong/ / ...
- iOS 自定义控件开发(上)
工作需要,最近在进行iOS方面的图表工作.找了很多第三方库都无法实现效果,所以决定自己写一个控件. <iOS 自定义控件开发(上)> <iOS 自定义控件开发(中)> #0 目 ...
- 在iOS App的图标上显示版本信息
最近读到一篇文章(http://www.merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/)介绍了一种非 ...
随机推荐
- django--之登录表单提交
前端代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- Python中的不同进制的语法和转换
不同进制的书写方式 八进制(Octal) 0o377 十六进制(Hex) 0xFF 二进制(Binary) 0b11111111 不同进制之间的转换 python提供了三个内置的函数,能够用来在不同进 ...
- linux下Tomcat shutdown无效
问题: linux下Tomcat shutdown无效 linux下关闭tomcat后,发现重新启动Tomcat后.port号提示被占用, 原因: 这时可能是项目中的后台线程或者socket依旧在执行 ...
- 添加github ssh 公钥
1.在控制台输入命令: ssh-keygen -t rsa -C "github上的邮箱地址" 2.将公匙复制后添加到github网站: id_rsa.pub文件 3.测试是 ...
- beego——控制器函数
基于beego的Controller设计,只需要匿名组合beego.Controller就可以,如下所示: type xxxController struct { beego.Controller } ...
- git命令与协同开发
一 git命令 1.简单命令 git init # 初始化 (建立git 版本相关文件关系都放这里) git config --global user.email "you@example. ...
- Codeforces Round #385 (Div. 1) C. Hongcow Buys a Deck of Cards
地址:http://codeforces.com/problemset/problem/744/C 题目: C. Hongcow Buys a Deck of Cards time limit per ...
- alias指令别名和 sshpass命令简化ssh登陆
在之前的一篇博文中 ubuntu下关于profile和bashrc中环境变量的理解 提到过可以编辑bashrc文件,vim ~/.bashrc,来编写自己的小指令,就是给长指令取个简单的别名.比如b ...
- Linux mount/unmount命令(6/16)
linux是一个优秀的开放源码的操作系统,可以运行在大到巨型小到掌上型各类计算机系统上,随着 linux系统的日渐成熟和稳定以及它开放源代码特有的优越性,linux在全世界得到了越来越广泛的应用.现在 ...
- ubuntu开启ROOT用户自动登录教程
ub默认不开root很纠结,虽说是为了安全,但对于linux老鸟,老是sudo烦的很 开root方法: sudo passwd root 输入root密码 sudo gedit /etc/gdm/cu ...