如何使用UIStoryboard segues将数据从一个View传递到IOS中的其他视图? [英] How to pass data from one View to other view in IOS using UIStoryboard segues?

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

问题描述

我正在使用 Xcode 4.3.1 。我使用Storyboard创建了UI,它有许多View Controller。

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.

上述问题的确切功能

我在第一个视图中有一个按钮控制器

当触发按钮时,它会弹出一些数据的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

}

}

之前曾问过这个问题,但我无法得到解决方案,这就是为什么我要再问一次。为此道歉。
感谢您的帮助

This question was asked before but i couldn't get the solution thats why i am asking again. Apologise for that. Thanks for your help guys

推荐答案

您可以在prepareForSegue调用中明确地传递数据。

You can pass the data explicitly and in storyboard that is with the prepareForSegue call.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([[segue identifier] isEqualToString:@"ContactsViewControllerSegue"]){
        ContactsViewController *cvc = (ContactsViewController *)[segue destinationViewController];
        cvc.contacts = self.contacts;
        cvc.delegate = self;
    }
}

如需完整教程,请查看网站

For a full tutorial check out this website.

要以编程方式触发segue,您可以查看 Apple Docs ,但这是他们的方向更改示例。

To programmatically trigger the segue you can check the Apple Docs, but here is their example on orientation change.

- (void)orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
        !isShowingLandscapeView)
    {
        [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self];
        isShowingLandscapeView = YES;
    }
// remainder of example omitted....
}

所以你会在抖动停止时触发segue,然后在prepareForSegue方法中准备下一个viewController。

So you will trigger the segue when shaking stops, and then prepare the next viewController in the prepareForSegue method.

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

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