可在AppDelegate.h中定义,之后可全局使用。
NSNotificationCenter *notificationCenter;
在.m文件中:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
self.notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(trackNotifications:) name:nil object:nil];
}
- (void) trackNotifications: (NSNotification *) notification
{
id nname = [notification name];
if([nname isEqual:@"***"])
{
......
}else if([nname isEqual:@"***"])
{
......
}else if([nname isEqual:@"***"])
{
......
}else if([nname isEqual:@"***"])
{
......
}else if([nname isEqual:@"***"])
{
......
}
}
在别的地方使用的时候,只需要调用[[NSNotificationCenter defaultCenter] postNotificationName:@"about" object:@""];
分享到:
相关推荐
SFObservers, NSNotificationCenter和KVO自动删除观察者 在任何项目中,我不再使用 SFObservers,但仍然会接受请求的请求。命令行目SFObservers是在NSNotificationCenter和KVO中为观察者 Pattern 添加自动删除的类别...
iOS 通知 转发
NULL 博文链接:https://o0o0o0o.iteye.com/blog/645602
IOS中经常会使用到NSNotification和delegate来进行一些类之间的消息传递,这篇文章主要介绍了iOS NSNotificationCenter使用小结,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
详细说明了NSNotificationCenter的使用,包括各个参数的使用
通知中心(NSNotificationCenter)采用单例的模式,整个系统只有一个通知中心,通过如下代码获取: //获取通知中心 [NSNotificationCenter defaultCenter]; 注册通知监听器方法: //observer为监听器 //aSelector...
OC-NSNotificationCenter.异步线程下载图片zip
iOS基础——通知代理之NSNotificationCenter、Delegate
IZEvent IZEvent是NSNotificationCenter的纯Swift替代方案。 它努力做到简单,安全和简单。 Pro的NSNotificationCenter上: 内存安全:不会发生内存泄漏,也不需要在deinit中删除观察者线程安全:默认情况下将事件...
iOS基础——通知代理之NSNotificationCenter、Delegate
FXNotifications, 一个NSNotificationCenter的替代 API 命令行目FXNotifications是 NSNotificationCenter的一种类别,提供了基于基于的API,更简单易用,并避免了官方API的不同内存漏洞。有关更多详细信息,请参见...
iOS开发基础-NSNotificationCenter(通知中心)通知发布者和监听者示例,代码DEMO附带详细注释。有错误的地方欢迎提出。
NULL 博文链接:https://andydufresneone.iteye.com/blog/1028462
一个简单的NSNotificationCenter的使用例子Demo,适合初学者。另外一个简单的UI效果是在tab bar的tab上面加上数字badge。 小编注:感谢开发者@Promise松 分享代码于本站。 Code4App编译测试,适用环境:Xcode ...
A 页有N+1UIView,B页执行一个操作,A的N+1Uiview要修改,可以通过Delelgate实现,蛋有的时候无法实现时,选用消息模式
ios demo,NSNotificationCenter,app进入后台时的调用和就、进入前台时的调用。
1.提供添加观察者、发送通知接口 2.封装类中已实现remove观察者 3.通过block回传发送者发送的信息
NULL 博文链接:https://justcoding.iteye.com/blog/1476165