添加观察者(无参数):
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(refresh) name:@"update_index_view" object:nil];
发送通知(无参数):
//根据网络状态,判断首页的显示内容
[[NSNotificationCenter defaultCenter] postNotificationName:@"update_index_view" object:nil userInfo:nil];
添加观察者(有参数):
/刷新首页UI
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(mainThread_handleURLStartup:) name:@"startup_from_url" object:nil];
-(void) mainThread_handleURLStartup:(NSNotification *) note
{
NSDictionary *info = [note userInfo];
NSString *url_result = [[note userInfo] objectForKey:@"url_result"];
NSLog(@"url_result : %@",url_result);
NSLog(@"start from url , information: %@", info);
NSString *startupResult = [info objectForKey:@"url_result"];
NSLog(@"startup url result: %@", startupResult);
}
发送通知(有参数):
NSString *appIndentier = @"kuainiao://";
NSRange range = NSMakeRange(0, [appIndentier length]);
NSLog(@"_startupURL is %@", _startupURL);
NSString *schema = [_startupURL substringWithRange:range];
if([schema isEqualToString:appIndentier])
{
NSString *startupParam = [_startupURL substringFromIndex:[appIndentier length]];
NSLog(@"startupParam is %@",startupParam);
NSDictionary *info = [NSDictionary dictionaryWithObject:startupParam forKey:@"url_result"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"startup_from_url" object:nil userInfo:info];
}
分享到:
相关推荐
SFObservers, NSNotificationCenter和KVO自动删除观察者 在任何项目中,我不再使用 SFObservers,但仍然会接受请求的请求。命令行目SFObservers是在NSNotificationCenter和KVO中为观察者 Pattern 添加自动删除的类别...
iOS 通知 转发
iOS开发基础-NSNotificationCenter(通知中心)通知发布者和监听者示例,代码DEMO附带详细注释。有错误的地方欢迎提出。
通知中心(NSNotificationCenter)采用单例的模式,整个系统只有一个通知中心,通过如下代码获取: //获取通知中心 [NSNotificationCenter defaultCenter]; 注册通知监听器方法: //observer为监听器 //aSelector...
iOS基础——通知代理之NSNotificationCenter、Delegate
IOS中经常会使用到NSNotification和delegate来进行一些类之间的消息传递,这篇文章主要介绍了iOS NSNotificationCenter使用小结,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
观察员中心基于 ,在 obj-c 中为多观察者模式创建一个观察者中心。超越 PLObservers 的优势将被观察者和被观察者解耦; 订阅指定键的新功能; 使用更方便。用法 1. without keyADD_OBSERVER(protocol, observer)...
iOS基础——通知代理之NSNotificationCenter、Delegate
1.提供添加观察者、发送通知接口 2.封装类中已实现remove观察者 3.通过block回传发送者发送的信息
NSNotificationCenter 带参数发送 41 延时一段时间执行某一函数 42 无99美金证书联机开发 42 获取IOS设备的基本信息 42 用NSDateFormatter调整时间格式的代码 42 UIView设置成圆角方法 43 iPhone里的frame和bounds...
通知中心 通知分派机制,可将信息广播到注册的观察者。 该库的工作方式类似于Objective-C和Swift NSNotificationCenter也类似于Android平台中的BroadcastReceiver 。 通知分派机制,可将信息广播到注册的观察者。 ...
一个简单的NSNotificationCenter的使用例子Demo,适合初学者。另外一个简单的UI效果是在tab bar的tab上面加上数字badge。 小编注:感谢开发者@Promise松 分享代码于本站。 Code4App编译测试,适用环境:Xcode ...
####一、@妙玄 提供思路:外层包装一个Wrapper对象来感知Observer的释放,通过Wrapper对象来移除通知. NSNotificationCenter加一个category, 添加一个associatedObject为一个数组. 替换NSNotificationCenter的 ...
Pro的NSNotificationCenter上: 内存安全:不会发生内存泄漏,也不需要在deinit中删除观察者线程安全:默认情况下将事件传递到主线程类型安全:纯Swift实现意味着所有内容都在编译时(而不是运行时)进行类型检查...
NULL 博文链接:https://o0o0o0o.iteye.com/blog/645602
详细说明了NSNotificationCenter的使用,包括各个参数的使用
OC-NSNotificationCenter.异步线程下载图片zip
A 页有N+1UIView,B页执行一个操作,A的N+1Uiview要修改,可以通过Delelgate实现,蛋有的时候无法实现时,选用消息模式