質問

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

Issue

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

My question is

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.

Exact function for the above question

I am having an button in First View Controller

enter image description here

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

enter image description here

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

Code

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

役に立ちましたか?

解決

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.

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....
}

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

他のヒント

You need to create string object in SecondViewController and set Property(nonatomic,retain) and synthesize it and after below code add when you push controller.

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

objSecondViewController.strtitle=@"Your data";
[self.navigationController pushViewController:objSecondViewController animated:YES];
[objSecondViewController release];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top