2012-08-03 41 views
1

我正在使用Xcode 4.3.1。我使用具有许多视图控制器的Storyboard创建了UI。如何使用UIStoryboard segues将数据从一个View传递到IOS中的其他视图?

问题

在我的应用我使用ShakeGesture。虽然我正在做一些操作,但它的工作正常。但是,当摇晃停止时,我需要将一些值传递给另一个View控制器来显示它。我看过很多文章,说如何点击按钮时传递价值,但没有人与我的问题有关。

如果你解决这将是巨大的我的问题

我的问题是

如何获得晃动停止后,从一个视图到另一个视图控制器值传递?

我正在寻找任何示例或教程。非常感激。

首先针对上述问题

我有一个按钮控制器

enter image description here

确切功能当按钮触发它会弹出pickerview一些DATAS。当用户选择它时,选取器值将替换按钮值。

enter image description here

然后振动发生时它停止我必须将数据传递到其他视图控制器。

代码

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

} 

}

这个问题被问过,但我无法得到解决,多数民众赞成为什么我再次问。为此道歉。 感谢您的帮助球员

+0

如何使用**协议**?这正是你需要实现的。 – 2012-08-03 09:23:30

+0

看到我的答案在这里:http://stackoverflow.com/a/11708506/530432 – 2012-08-03 09:26:05

+0

看看这个[**答案**](http://stackoverflow.com/questions/10052594/xcode-update-viewcontroller -label-text-from-different-view/10052641#10052641)。我已经解释了如何实现协议。 – 2012-08-03 09:28:24

回答

2

您可以显式传递数据,并且在prepareForSegue调用的故事板中传递数据。

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

查看完整教程查看website

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

- (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。

+0

谢谢你的答案..我只是困惑如何准备为segue调用时震动停止.. – GoCrazy 2012-08-03 10:52:37

+0

我已经添加了代码示例以编程方式触发segue。 – 2012-08-03 13:41:34

+0

作品像魅力..这是我期待..谢谢 – GoCrazy 2012-08-03 15:30:32

0

您需要在SecondViewController中创建字符串对象并设置属性(非原子,保留)并合成它,并在下面的代码添加时,您推控制器。

SecondViewController *objSecondViewController=[[SecondViewController alloc] 
initWithNibName:@"SecondViewController" bundle:nil];    

[email protected]"Your data"; 
[self.navigationController pushViewController:objSecondViewController animated:YES]; 
[objSecondViewController release]; 
+0

我以这种方式累了,但它导致异常 – GoCrazy 2012-08-03 09:47:57

相关问题