Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode ios 6 shake motion calls IBaction from previous view

I'm a bit new to app development. In a viewController ( VPviewController ) i have the following code:

- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    if (motion == UIEventSubtypeMotionShake){       
        [self startGame:nil];
    }   
}

In a different viewController ( VPgameViewController ) i have a different MotionShake event:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    if(event.subtype == UIEventSubtypeMotionShake){
        if(count < 3 ){

            [self changeText:nil];
            AudioServicesPlaySystemSound(1016);
            count++;

         }else{

            count = 0;
            AudioServicesPlaySystemSound(1024);
            UIStoryboard *storyboard = self.storyboard;
            VPpoepViewController *shit = [storyboard instantiateViewControllerWithIdentifier:@"PoepViewController"];
           shit.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
           [self presentViewController:shit animated:YES completion:nil];
        }
    }
}

When i'm in the VPgameView and i shake the Iphone it's also calling the startGame function which is in a different viewController shake event.

How can i stop this?

like image 441
Wesley Van De Korput Avatar asked Nov 21 '12 15:11

Wesley Van De Korput


1 Answers

Sounds like you have to unsubscribe your VPViewController from receiving the shake event notifications in its viewWillDisappear: function.

Generally, if you want your viewController to receive certain event notifications only when visible you should subscribe to the notification in the viewWillAppear: function and unsubscribe in the viewWillDisappear: function.

like image 161
kadam Avatar answered Nov 13 '22 07:11

kadam