2011-10-20 5 views
1

제 생각에는 UIBarButton (iPad)에서 표시 할 수있는 작업 시트가 있습니다. 사용자가 홈 화면으로 돌아가서 앱을 잠그면 사용자가 보안을 위해 비밀번호를 입력해야하는 잠금 화면이 표시됩니다. 그러나 popover가 배경으로 들어가기 전에 해체되지 않으면 여전히 lockscreen 위에 표시됩니다. UIActionSheet는 App Delegate가 아닌 해당 VC의 속성입니다.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는 응용 프로그램이 backrgound에서 되돌아오고 pcode 검사로 이미 있던 vc의 ontop으로로드 될 때 표시되는 VC입니다. – Jon

+0

괜찮습니다. 해당 코드를 제시하고 해당 actionSheet에 대한 참조를 갖는보기 컨트롤러로 작업하십시오. 응용 프로그램이 사임 할 때 actionSheet를 닫고 반환 할 때 더 이상 표시되지 않습니다. – NJones

+0

Worked! 이게 제가 dealloc에 ​​넣은 것입니까? '[[NSNotificationCenter defaultCenter] removeObserver : 자체 이름 : UIApplicationWillResignActiveNotification 객체 : nil]; ' – Jon

관련 문제