如何把当前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];
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];
相关文章推荐
- UINavigationControll采用pushViewController后如何去掉左边的返回按钮
- UITabbarController点击tabbar选项返回当前viewController最顶层
- 如何寻找到当前ViewController?
- 如何在多次presentViewController后直接返回最底层界面
- UITabbarController点击tabbar选项返回当前viewController最顶层
- 自定义tabbarcontroller 和 双击自定义的btn 的时候使当前viewcontroller 返回最顶层
- 如何让UIView中的Button点击之后跳转到另一个ViewController上去,ViewController上也有一个按钮 可以返回
- UINavigationControll采用pushViewController后如何去掉左边的返回按钮
- IOS ViewController切换动画以及如何返回
- 使用NavigationController, 或ModalViewController实现旋转新视图横屏,再旋转返回
- iphone 使用popViewController如何避免内存泄露
- MVC如何分离Controller与View在不同的项目
- MVC中,如果从controller返回的不是一个html,而是一个文本,使用AJAX中如何获取?
- 如何解散modalViewController的modalViewController
- 如何让你的UINavigationController.rootViewController 占领这个屏幕?UINavigationController UIView fullScreen
- 如何用SplitViewController控件
- 如何实现pushViewController:animated:的不同页面转换特效?
- MVC中,如果从controller返回的不是一个html,而是一个文本,使用AJAX中如何获取?
- 如何在Joomla的controller中关联Model和View
- 如何在controller中获得view实例