【IPhone开发】NSNotificationCenter观察者模式给主线程发送通知
2012-09-03 11:28
489 查看
添加观察者(无参数):
发送通知(无参数):
添加观察者(有参数):
发送通知(有参数):
[[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]; }
相关文章推荐
- iPhone开发之NSNotificationCenter(通知)的使用方法
- Cocos2D-x游戏开发之二十三:CCNotificationCenter观察者模式(2)-不同层之间事件的发送和接受
- 【转载】iPhone开发之NSNotificationCenter(通知)的使用方法
- iPhone开发之NSNotificationCenter(通知)的使用方法
- iPhone开发之NSNotificationCenter(通知)的使用方法
- iPhone开发之NSNotificationCenter(通知)的使用方法
- iOS开发之NSNotificationCenter(通知)的使用方法
- Cocos2D-x游戏开发之:CCNotificationCenter观察者模式基础
- ios开发中的基本设计模式(代理,观察者,MVC,单例,策略,工厂,MVVM,原型,Target-Action,通知(notification)机制)
- iOS开发之:NSNotificationCenter(通知)的使用方法
- iOS开发之NSNotificationCenter(通知)使用介绍
- 关于重复接收NSNotificationCenter发送的通知的问题
- Cocos2D-x游戏开发之二十二:CCNotificationCenter观察者模式基础(1)
- iOS开发之NSNotificationCenter(通知)的使用方法
- 安卓开发观察者模式应用-一个service通知多个activity更新ui的实现
- 观察者模式——CCNotificationCenter
- 【iOS开发】观察者模式-通知的使用及深入理解
- IOS通知中心(观察者模式)[NSNotificationCenter defaultCenter]
- iOS开发之NSNotificationCenter详解
- 【深入浅出ios开发】NSNotificationCenter