您的位置:首页 > 其它

如何把当前ViewController的值返回给上一ViewController?

2015-03-25 22:56 405 查看
首先生成第一个有三个按钮的界面

UINavigationController *navcon = [[UINavigationController alloc]init];

PsychologistViewController *pvc = [[PsychologistViewController alloc] init];

[navcon pushViewController:pvc animated:NO];

[pvc release];

[window addSubview:navcon.view];

然后生成第二个表示和按钮相对应的“心情”界面

HappinessViewController *hvc = [[HappinessViewController alloc]init];

[self.navigationController pushViewController:hvc animated:YES];

[hvc release];

按下Edit之后 出现第三个“编辑”界面

HappinessEditViewController *hevc = [[HappinessEditViewController alloc]init];

[self.navigationController pushViewController:hevc animated:YES];

[hevc release];

在第三个界面编辑完画面之后
按下“Done"按钮时 用下列函数返回第二个View

[self.navigationController popViewControllerAnimated:YES];

问题来了

想要将第三个View中的 RGB值,线条颜色,和一个实数(是曲线相关参数)。

怎么传值给第二个View 并让它刷新显示呢?

解决方法很多:

1、通过NSNotificationCenter 实现

发送结果:

[[NSNotificationCenter defaultCenter]postNotificationName:myNotifName object:nil userInfo:myInfo];

HappinessViewController *hvc = [self.navigationController.viewControllers objectAtIndex:n-2]; //n為最頂的index

[self.navigationController popToViewController:hvc animated:YES];

接收处理:

[[NSNotificationCenter defaultCenter]addObserverForName:myNotifNameobject:nil
queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *note) {

NSDictionary *dic =(NSDictionary *) note.userInfo;

NSLog(@"接收到的数据=%@",dic);

}];

2、通过.h文件对外开放属性imageV.image实现

HappinessViewController
*hvc = [self.navigationController.viewControllers objectAtIndex:n-2]; //n為最頂的index

hvc.imageV.image = imageV1.image; //加入你的数据

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