Domanda

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.

EDIT

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

}

}

Thanks for your help guys

È stato utile?

Soluzione

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];

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

Altri suggerimenti

to detect the end of the shake gesture, implement motionEnded:withEvent in your view controller.

- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
 if (event.type == UIEventSubtypeMotionShake)
 {
   // perform the seque
 }
}

using techniques described above for passing data to this view controller

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top