title: Dismiss UIActionSheet from AppDelegate
body: <p>In my view, I have an actionsheet that may be presented from a UIBarButton (iPad).  If user goes to homescreen and back, app shows a lock screen wehre user must enter password for security.  But if the popover wasn't dismised before going into background, it is still showing on top of lockscreen.  The UIActionSheet is a property of that VC, not the App Delegate.</p>
  
  <p>The method in my delegate is:</p>
  
  <pre><code>- (void)applicationDidBecomeActive:(UIApplication *)application
  {
      NSLog(@"STATUS - Application did become active");
      [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
      [_notActiveTimer invalidate];
      _notActiveTimer = nil;
  
      [[NSNotificationCenter defaultCenter] postNotificationName:@"_application_background" object:self userInfo:NULL];
  
      LockScreen *vc = [[[LockScreen alloc] initWithNibName:@"LockScreen" bundle:nil] autorelease];
      vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
      vc.showFullUsernamePasswordLogin = TRUE;
      [self.splitView presentModalViewController:vc animated: YES];
  }
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>- (IBAction)showeRXActionSheet:(id)sender
  {
      if (self.actionSheet != nil) {
          [self.actionSheet dismissWithClickedButtonIndex:0 animated:NO];
      }
  
      if (!self.eRXActionSheet)
      {
          UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"eRX Menu" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"New eRX", @"eRX Refills", nil];
          sheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
          self.eRXActionSheet = sheet;
          [sheet release];
  
          [self.eRXActionSheet showFromBarButtonItem:sender animated:YES];
  
          return;
      }
  
      [self.eRXActionSheet dismissWithClickedButtonIndex:self.eRXActionSheet.cancelButtonIndex animated:YES];
      self.eRXActionSheet = nil;
  }
  
  - (IBAction)actionButtonClicked:(id)sender
  {
      if (self.eRXActionSheet != nil) {
          [self.eRXActionSheet dismissWithClickedButtonIndex:0 animated:NO];
      }
  
      if (!self.actionSheet)
      {
          UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Action Menu" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Help", @"Lock", @"Log Out", nil];
          sheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
          self.actionSheet = sheet;
          [sheet release];
  
          [self.actionSheet showFromBarButtonItem:sender animated:YES];
  
          return;
      }
  
      [self.actionSheet dismissWithClickedButtonIndex:self.actionSheet.cancelButtonIndex animated:YES];
      self.actionSheet = nil;
  }
  
  - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  {
      if (actionSheet == self.eRXActionSheet)
      {
          if (buttonIndex == 0)
          {
              [self erxButtonClicked];
          }
          else if (buttonIndex == 1)
          {
              [self erxRefillButtonClicked];
          }
      }
      else
      {
          if (buttonIndex == 0)
          {
              [self helpButtonClicked];
          }
          else if (buttonIndex == 1)
          {
              [self lockButtonClicked];
          }
          else if (buttonIndex == 2)
          {
              [self logOut];
          }
      }
  }
  
  - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
  {
      self.eRXActionSheet = nil;
      self.actionSheet = nil;
  }
  </code></pre>