Xcode ios 6 shakes movement calls of IBaction from previous view

I am a little new to application development. In viewController (VPviewController), I have the following code:

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

In another viewController (VPgameViewController), I have another 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 am in VPgameView and I shake Iphone, it also calls the startGame function, which is in another shakeController event.

How can i stop this?

+6
source share
1 answer

It looks like you need to unsubscribe from the VPViewController from receiving shake event notifications in your viewWillDisappear: function.

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

+2
source

All Articles