您的位置:首页 > 其它

几个页面跳转以及传值(通知传值)

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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: