views:

431

answers:

1

This is a fun one... I have an application that has a help screen and is displayed as a modal view. The main view has an action that occurs when the device is shaken. I do not want the action to occur (sounds are played) when the help screen has been displayed.

I have tried a few things... here is my code:

To display the help screen:

- (IBAction)helpButtonPressed:(id) sender {
    helpViewController = [[HelpViewController alloc] init]; 
    [self presentModalViewController:helpViewController animated:YES];
}

To release the help screen:

- (IBAction)buttonPressed:(id) sender {
    [self dismissModalViewControllerAnimated:YES];
}

I tried the following with no success:

if ([helpViewController.view isHidden ]) {
 NSLog(@"Shake -- helpView is loaded");
} else {
 NSLog(@"Shake -- helpView is not loaded");
}


if ([helpViewController isViewLoaded]) {
 NSLog(@"Shake -- helpView is loaded");
} else {
 NSLog(@"Shake -- helpView is not loaded");
}

if ([self isViewLoaded]) {
 NSLog(@"Shake -- helpView is loaded");
} else {
 NSLog(@"Shake -- helpView is not loaded");
}

What I was thinking is if there is a function to allow me to detect if the help view is showing, I will return without playing the sounds when the device is shaken....

Any ideas?

A: 

I'm assuming that the view controller which loads the modal controller is also the view controller that responds to the shake action. If that's the case, then you can use the parent view controller's modalViewController property to see whether the modal controller is active:

if(self.modalViewController != nil) {
    // Modal view controller is active; do nothing
    NSLog(@"Shake -- helpView is loaded");
    return;
} else {
    // No modal view controller; take action
    NSLog(@"Shake -- helpView is not loaded");
    [self performSomeAction];
}
Tim
Works perfectly! Thanks!
iPhone Guy