几个页面跳转以及传值(通知传值)
2015-01-13 00:25
148 查看
A→B→C→D→A
其中A不是根目录,但是在D上还要跳转回去,并且不用alloc,这时我们可以用如下方法
[self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex: ([self.navigationController.viewControllers count] -4)] animated:YES];
并且D要传值给A,这时通知就很好用了
通知传值(一个发送者,一堆接收者,不需要代理协议,直接通过系统的通知中心工作notificationCenter)
在传值页面
首先弄个系统通知中心
NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
NSNotification * notify = [NSNotification notificationWithName:@"regisonName" object:[NSString stringWithFormat:@"%@",[self.dataArray[indexPath.row] objectForKey:@"name"]]];
//第一个参数是通知的名字,就是标示,名一个名字,以备你用这个名字去找对象 第二个参数就是你要传的值,接收要接收的值,这个值必须是对象
[center postNotification:notify];
在接收页面
//NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(setRegionTitle:)
name:@"regisonName"
object:nil];
//第一个参数:将要干活的对象 第二个参数(方法名,将要干的活) 第三个参数(干活的名字,要与发送者一致) 第四个参数(系统的,暂时不用管)
- (void)setRegionTitle:(NSNotification *)notify{
NSString * object = [notify object];
[_regionButton setTitle:object forState:UIControlStateNormal];
[_regionButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
其中A不是根目录,但是在D上还要跳转回去,并且不用alloc,这时我们可以用如下方法
[self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex: ([self.navigationController.viewControllers count] -4)] animated:YES];
并且D要传值给A,这时通知就很好用了
通知传值(一个发送者,一堆接收者,不需要代理协议,直接通过系统的通知中心工作notificationCenter)
在传值页面
首先弄个系统通知中心
NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
NSNotification * notify = [NSNotification notificationWithName:@"regisonName" object:[NSString stringWithFormat:@"%@",[self.dataArray[indexPath.row] objectForKey:@"name"]]];
//第一个参数是通知的名字,就是标示,名一个名字,以备你用这个名字去找对象 第二个参数就是你要传的值,接收要接收的值,这个值必须是对象
[center postNotification:notify];
在接收页面
//NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(setRegionTitle:)
name:@"regisonName"
object:nil];
//第一个参数:将要干活的对象 第二个参数(方法名,将要干的活) 第三个参数(干活的名字,要与发送者一致) 第四个参数(系统的,暂时不用管)
- (void)setRegionTitle:(NSNotification *)notify{
NSString * object = [notify object];
[_regionButton setTitle:object forState:UIControlStateNormal];
[_regionButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
相关文章推荐
- IOS_简单地页面跳转以及NSNotificationCenter(通知中
- 微信小程序实现页面跳转传值以及获取值的方法分析
- iOS 页面跳转传值,属性传值,代理传值,代码块传值,单例传值,通知传值
- android页面的跳转以及传值
- IOS 页面之间的跳转以及传值
- js跳转页面并传值以及localStorage的用法
- [HTML]js实现页面跳转,页面A跳到另一个页面B.以及页面传值(中文)
- 微信小程序页面跳转传值以及获取值方法
- js 刷新页面和跳转页面的几个办法本文来自: 陈华IT笔记!本文详细地址:http://www.chhua.com/it/
- JS控制的几种页面跳转方式和传值
- JS控制的几种页面跳转方式和传值
- asp.net 页面间传值与跳转的区别
- 【原】页面跳转以及表单提交中有中文的解决办法
- 一起学Windows phone 7开发(二.页面间跳转与传值)
- PHP Header用于页面跳转要注意的几个问题总结
- 原始的JAVASCRIPT实现的WEB页面跳转以及页面间传值方法
- ASP.NET中的WEB页面跳转以及页面间传值方法
- asp.net 页面间传值与跳转的区别
- .NET中LinkButton控件进行数据绑定,页面跳转并传值
- DNN下布局用户控件以及设置页面跳转