ios 通知
2016-01-09 14:36
405 查看
//添加
字典,将label的值通过key值设置传递
NSDictionary
*dict =[[NSDictionary alloc]
initWithObjectsAndKeys:self.textFieldOne.text,@"textOne",self.textFieldTwo.text,@"textTwo",
nil];
//创建通知
NSNotification *notification =[NSNotification notificationWithName:@"tongzhi"
object:nil userInfo:dict];
//通过通知中心发送通知
[[NSNotificationCenter defaultCenter] postNotification:notification];
[self.navigationController
popViewControllerAnimated:YES];
在发送通知后,在所要接收的控制器中注册通知监听者,将通知发送的信息接收
- (void)viewDidLoad {
[super viewDidLoad];
//注册通知
[[NSNotificationCenter
defaultCenter]
addObserver:self
selector:@selector(tongzhi:)
name:@"tongzhi"
object:nil];
}
- (void)tongzhi:(NSNotification *)text{
NSLog(@"%@",text.userInfo[@"textOne"]);
NSLog(@"-----接收到通知------");
}
移除通知:removeObserver:和removeObserver:name:object:
其中,removeObserver:是删除通知中心保存的调度表一个观察者的所有入口,而removeObserver:name:object:是删除匹配了通知中心保存的调度表中观察者的一个入口。
这个比较简单,直接调用该方法就行。例如:
[[NSNotificationCenter defaultCenter] removeObserver:observer name:nil object:self];
注意参数notificationObserver为要删除的观察者,一定不能置为nil。
字典,将label的值通过key值设置传递
NSDictionary
*dict =[[NSDictionary alloc]
initWithObjectsAndKeys:self.textFieldOne.text,@"textOne",self.textFieldTwo.text,@"textTwo",
nil];
//创建通知
NSNotification *notification =[NSNotification notificationWithName:@"tongzhi"
object:nil userInfo:dict];
//通过通知中心发送通知
[[NSNotificationCenter defaultCenter] postNotification:notification];
[self.navigationController
popViewControllerAnimated:YES];
在发送通知后,在所要接收的控制器中注册通知监听者,将通知发送的信息接收
- (void)viewDidLoad {
[super viewDidLoad];
//注册通知
[[NSNotificationCenter
defaultCenter]
addObserver:self
selector:@selector(tongzhi:)
name:@"tongzhi"
object:nil];
}
- (void)tongzhi:(NSNotification *)text{
NSLog(@"%@",text.userInfo[@"textOne"]);
NSLog(@"-----接收到通知------");
}
移除通知:removeObserver:和removeObserver:name:object:
其中,removeObserver:是删除通知中心保存的调度表一个观察者的所有入口,而removeObserver:name:object:是删除匹配了通知中心保存的调度表中观察者的一个入口。
这个比较简单,直接调用该方法就行。例如:
[[NSNotificationCenter defaultCenter] removeObserver:observer name:nil object:self];
注意参数notificationObserver为要删除的观察者,一定不能置为nil。
相关文章推荐
- iOS学习之路-简单汤姆猫
- iOS中 KVC\KVO和通知三者之间的小结
- 【iOS】判断NSString字符串为空
- iOS: 枚举类型 enum,NS_ENUM,NS_OPTIONS
- iOS学习笔记:runtime(1)
- iOS 退出应用程序
- ios字符串截取/数据存入数组
- iOS使用自定义字体
- 关于iOS中如何给字体加粗的问题总结
- ios字典用字符串输出
- 如何创建iOS环境下的cordova插件,让其运用到iOS项目中
- 在iOS中实现类似安卓自动消失提示框
- ios身份证key字典排序
- 数组中有字典、对字典进行升序,然后运用描述器进行排序,更改字典让中元素的信息iOS 6习题
- iOS_SpriteKit_03_精灵平移拖动
- ios私有api查询
- iOS将一个图片平均分成两部分
- iOS加密方式:RSA DES MD5
- IOS清理缓存的几种方法
- ios 清理缓存