2011-10-20 2 views
1

私の見解では、UIBarButton(iPad)から提示されるアクションシートがあります。ユーザーがホーム画面に戻って戻ると、ユーザーはセキュリティのためにパスワードを入力する必要があります。しかし、ポップオーバーがバックグラウンドに入る前に解体されなかった場合、それはまだロック画面の上に表示されています。 UIActionSheetは、そのVCのプロパティであり、App Delegateではありません。AppDelegateのUIActionSheetを解除する

私のデリゲートのメソッドは次のとおりです。

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

コード:

- (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; 
} 

答えて

1

これは、あなたが欲しいものを行う必要があります。

-(void)dismissSheet{ 
    if (self.actionSheet){ 
     [self.actionSheet dismissWithClickedButtonIndex:0 animated:NO]; 
    } 
} 

-(void)viewDidLoad{ 
    [super viewDidLoad]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissSheet) name:UIApplicationWillResignActiveNotification object:nil]; 
     // Your other setup code 
} 

UIApplicationDidEnterBackgroundNotificationを使用することもできますが、これはアプリケーションフローにとって意味があります。

deallocでオブザーバを削除することを忘れないでください。

+0

アクションシートを表示するVCはlockscreen vcではありません。ロックスクリーンVCは、アプリケーションがバックグラウンドから戻ったときに表示されるVCで、ピンコードチェックとしてすでに存在していたvcのオンロードになります。 – Jon

+0

これは問題ありません。そのコードを、actionSheetを提示して参照するView Controllerに渡します。アプリケーションが終了すると、actionSheetが終了し、戻り時には表示されなくなります。 – NJones

+0

Worked!これは私がdeallocに入れたものですか? '[NSNotificationCenter defaultCenter] removeObserver:自己の名前:UIApplicationWillResignActiveNotificationオブジェクト:なし]; ' – Jon

関連する問題