通知跳转传值-姬云鹏
来源:互联网 发布:Windows的sleep 编辑:程序博客网 时间:2024/05/17 22:27
知 是在跳转控制器之间常用的传值代理方式,除了代理模式,通知更方便、便捷,一个简单的Demo实现通知的跳转传值.
输入所要发送的信息 ,同时将label的值通过button方法调用传递,
- (IBAction)buttonClick:(id)sender {
//添加 字典,将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。
- 通知跳转传值-姬云鹏
- 通知跳转传值-姬云鹏
- 通知跳转传值
- 几个页面跳转以及传值(通知传值)
- 安卓开发:发送任务栏通知,并实现传值、跳转
- 通知栏跳转问题
- 推送通知的跳转
- Notification通知,点击通知后跳转
- iOS 跳转系统通知、应用间跳转
- Android 点击通知栏 跳转
- 点击通知栏 跳转 Fragment
- [Object-c] 通知二 通知传值
- 通知传值
- NSNotification 通知传值
- 通知传值(NSNotificationCenter)
- 通知传值
- 通知传值(NSNotificationCenter)
- 通知传值
- jquery表单可编辑状态
- 是爱情,让我们直立行走
- iOS AES256/RSA/DES/MD5/sha-1 (加密/解密)
- Elasticsearch安装分词插件IK及问题解决
- 2016CCPC合肥站流水账
- 通知跳转传值-姬云鹏
- 软件开发工具总结
- Thinkpad 在Ubuntu下安装 Thinkfan(风扇控制)
- Python 基础笔记
- zookeeper安装配置
- 自适应相关
- 打印一个N*N的方阵,N为每边字符的个数( 3〈N〈20 )
- Codeforces 731B
- Python map