/* 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通知使用 书上案例 简单易懂的更多相关文章

  1. 做小图标还用sprite图?你out了!史上最简单易懂iconfont使用教程

    1.什么是iconfont? 说白了就是用图标制作而成的一套字体文件,本质是一个字体文件(扩展名是ttf\woff\svg的文件).它是用来制作网页常用小图标的一种方法.以下是天猫首页使用iconfo ...

  2. IOS xib在tableview上的简单应用(通过xib自定义cell)

    UITableView是一种常用的UI控件,在实际开发中,由于原生api的局限,自定义UITableViewCell十分重要,自定义cell可以通过代码,也可以通过xib. 这篇随笔介绍的是通过xib ...

  3. 史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS。

    重要的话 开头说,not for the RecyclerView or ListView, for the Any ViewGroup. 本控件不依赖任何父布局,不是针对 RecyclerView. ...

  4. IOS开发中UIBarButtonItem上按钮切换或隐藏实现案例

    IOS开发中UIBarButtonItem上按钮切换或隐藏案例实现案例是本文要介绍的内容,这个代码例子的背景是:导航条右侧有个 edit button,左侧是 back button 和 add bu ...

  5. Session小案例-----简单购物车的使用

    Session小案例-----简单购物车的使用 同上篇一样,这里的处理请求和页面显示相同用的都是servlet. 功能实现例如以下: 1,显示站点的全部商品 2.用户点击购买后,可以记住用户选择的商品 ...

  6. iOS通知的整理笔记

    iOS通知用于高耦合界面的传值确实方便快捷. 需要实现模态弹出的视图控制器上,有一个视图控制器可以导航.这必定要将这个视图控制器的导航视图控制器naVC.view添加到模态弹出的视图控制器presen ...

  7. 李洪强iOS经典面试题上

    李洪强iOS经典面试题上     1. 风格纠错题 修改完的代码: 修改方法有很多种,现给出一种做示例: // .h文件 // http://weibo.com/luohanchenyilong/ / ...

  8. iOS 自定义控件开发(上)

    工作需要,最近在进行iOS方面的图表工作.找了很多第三方库都无法实现效果,所以决定自己写一个控件. <iOS 自定义控件开发(上)> <iOS 自定义控件开发(中)> #0 目 ...

  9. 在iOS App的图标上显示版本信息

    最近读到一篇文章(http://www.merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/)介绍了一种非 ...

随机推荐

  1. 百度 验证码识别API 使用

    先到百度云申请文字识别API ,会给你一个API KEY和一个SECRET KEY,免费,一天最多500次请求. try: temp_url = 'https://aip.baidubce.com/o ...

  2. 【pip】【conda】

    1.指定python包安裝版本==  指定python包安裝源-i: pip2 -i https://pypi.tuna.tsinghua.edu.cn/simple 2.配置文件换源 vi ~/.p ...

  3. 流畅的python 14章可迭代的对象、迭代器 和生成器

    可迭代的对象.迭代器和生成器 迭代是数据处理的基石.扫描内存中放不下的数据集时,我们要找到一种惰性获取数据项的方式,即按需一次获取一个数据项.这就是迭代器模式(Iterator pattern). 迭 ...

  4. Pantone色卡——安全装备的面板、丝印及铭牌颜色设计参考

    可以参考上传文件<Pantone色卡电子版下载>

  5. SQL2000查看表的大小

    SQL2000查看表的大小 标签: sqlsql server数据库报表tableinsert 2011-06-08 11:47 4013人阅读 评论(0) 收藏 举报 SQL2000查看表的大小 本 ...

  6. PAT 1071 Speech Patterns[一般]

    1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For exam ...

  7. VK Cup 2018 - Round 1+Codeforces Round #470

    A. Primal Sport 题意:有两个人轮流玩游戏.给出数X(i-1),轮到的人需要找到一个小于X(i-1)的素数x,然后得到Xi,Xi是x的倍数中大于等于X(i-1)的最小的数.现在已知X2, ...

  8. java要注意的问题3

    十七.使用正则 正则表达式的结构摘录如下(来源: Oracle官网) 字符 x 字符x / 反斜杠 /0n 8进制值为0n的字符(0<=n<=7) /0nn   /0mnn 8进制值为0m ...

  9. mongodb-2.6.0 在win7 64下的安装和服务启动

    转自: http://blog.csdn.net/lingchen214/article/details/24537629 1   自定义安装到C:\mongodb目录下. 2  手动在C:\mong ...

  10. shiro配置

    web.xml <!-- Shiro Filter is defined in the spring application context: --> <!-- 1. 配置 Shir ...