如何将数据从一个视图传递到IOS中的另一个视图控制器? [英] How to pass data from one view to another view controller in IOS?

查看:207
本文介绍了如何将数据从一个视图传递到IOS中的另一个视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Xcode 4.3.1 .我使用具有许多视图控制器的Storyboard创建了UI.

I am using Xcode 4.3.1. I have created the UI using Storyboard which has many View Controllers.

问题

在我的应用中,我正在使用ShakeGesture.摇晃时,我正在执行一些操作,其工作正常.但是,当停止摇动时,我需要将一些值传递给另一个View控制器以显示它.我看到过很多帖子,说如何在单击按钮时传递值,但是没有人与我的问题有关.

In my app i am using ShakeGesture. While shaking i am doing some operations, its working fine. But, when shaking get stopped i need to pass some values to another View controller to display it. I have seen many post it says how to pass value when button clicked,but no one related with my problem.

如果您解决我的问题,那就太好了

It would be great if you solve my issue

我的问题是

在摇动停止后如何将值从一个View传递到另一个View控制器?

How to pass values from one View to another View controller after shaking get stopped?

我正在寻找任何示例或教程.非常感谢.

I am looking for any examples or tutorials. Much appreciated.

编辑

上述问题的精确函数

我在 First View Controller

按钮触发后,将弹出pickerview并显示一些数据.当用户选择它时,选择器值将替换按钮值.

When the button triggered it will popup pickerview with some datas. When the user selects it the picker value replaces the button value.

然后在停止时发生摇动,我必须将数据传递给其他视图控制器.

Then Shaking happens when it stopped i have to pass the data to other view controller.

代码

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake)
{
        // I need to pass data here. Thats i am confusing

}

}

感谢您的帮助人员

推荐答案

通过ctrl从情节提要中的第一个视图控制器拖动到第二个视图控制器来创建序列.单击segue并转到身份检查器(按command-option-3).在标识符字段中为其命名,说"Shaking Stopped".然后在您的运动终止方法中使用...

Create a segue by ctrl dragging from the first view controller to the second one in the storyboard. Click on the segue and go to the identity inspector (press command-option-3). In the identifier field give it a name, say "Shaking Stopped". Then in your motion ended method use...

 [self performSegueWithIdentifier:@"Shaking Stopped" sender:self];

这将使视图切换到第二个视图.然后在准备segue时将其更改为...(当然使用您自己的值)

This will make the view switch to your second one. Then in your prepare for segue change it to this...(of course using your own values)

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"Shaking Stopped"]) {
<The Second View Controller> *controller = segue.destinationViewController
        //change your values in the other view controller here 
        controller.someValue = self.someValue //an example

这篇关于如何将数据从一个视图传递到IOS中的另一个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆