0

Ich habe eine Ansicht Controller A, die Tabellenansicht und basierend auf Zeilenauswahl, ich werde modal öffnen eine andere Ansicht Controller B. Ich habe auch einen Inaktivitätstimer für meine Anwendung implementiert. Jetzt, wenn B präsentiert wird und A Controller präsentiert und aufgrund der Inaktivität des Benutzers, wird ein anderer View Controller Inactivity View Controller C modal über B geöffnet. Das heißt, ich habe A, dann B über A und C über B. Nun hat der Benutzer auf eine Schaltfläche von C geklickt, um sich abzumelden, und ich kann nur C ausschalten. Aber View Controller B wird nie abgewiesen.Wie Modal View Controller zu entlassen, wenn mehrere View-Controller angezeigt werden

Inaktivität wird mit Touch-Ereignis und Benachrichtigungen implementiert, und die Benachrichtigung stellt den Inactivity-View-Controller modal über der aktuellen Ansicht dar, wie im folgenden Code erwähnt.

- (void) applicationDidTimeout:(NSNotification *) notif 
{ 
    NSLog(@"Application Did Timeout ..."); 

    BCDSessionInactivityViewController *sessionView=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"InactivityViewController"]; 

    sessionView.modalPresentationStyle = UIModalPresentationFormSheet; 
    sessionView.preferredContentSize = CGSizeMake(838,340); 
    UIViewController *parentController = self.parentViewController; 
    NSLog(@"presenting view controller is %@", [parentController class]); 

    [[self topViewController]presentViewController:sessionView animated:YES completion:nil]; 


} 


- (UIViewController *)topViewController{ 
    return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController]; 
} 



- (UIViewController *)topViewController:(UIViewController *)rootViewController 
{ 
    if (rootViewController.presentedViewController == nil) { 
     return rootViewController; 
    } 

    if ([rootViewController.presentedViewController isMemberOfClass:[UINavigationController class]]) { 
     UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController; 
     UIViewController *lastViewController = [[navigationController viewControllers] lastObject]; 
     return [self topViewController:lastViewController]; 
    } 

    UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController; 
    return [self topViewController:presentedViewController]; 
} 

Gibt es eine Möglichkeit, ich kann Controller B auch entlassen?

In View Controller C-Methode, wo ich View Controller C, ich bearbeite den Code wie vorgeschlagen, aber View Controller B ist immer noch nicht entlassen.

- (IBAction)logoutbtn:(id)sender 
{ 
    NSLog(@"logout is called"); 
    if ([self.presentingViewController isKindOfClass:[BCDScanReviewViewController class]] || [[[F7CheckScanner instance]checkFrontScanned] isEqualToString:@"checkFrontScanned"]) 
     { 
      NSLog(@"check front scanned %@",[[F7CheckScanner instance]checkFrontScanned]); 
      [[F7CheckScanner instance]scanBackOfCheckNoData]; 
     } 
    [sessionTimer invalidate]; 
    sessionTimer = nil; 
    [[BCDTimeManager sharedTimerInstance]stopIdleTimer]; 

    [self dismissViewControllerAnimated:YES completion:^(){ 

     [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:^(){; 
      BCDThankYouViewController *thankuView=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ThankyouView"]; 
      [[self topViewController ]presentViewController:thankuView animated:YES completion:nil]; 
     }]; 
    }]; 



    UIViewController *parentController = self.presentingViewController; 
    NSLog(@"presenting view controller is %@", [parentController class]); 
    // [self dismissViewControllerAnimated:YES completion:^() { 
    //  [parentController performSegueWithIdentifier:COMMON_VC_TO_THANK_YOU_VC sender:self]; 
    // }]; 


} 
+0

Da Sie eine NavigationController verwenden, können Sie die "Abwicklungs" -Sequenz verwenden. Siehe Antwort [hier] (http://stackoverflow.com/a/17607083/2535467). – CaptJak

+0

Verwenden Sie den Abschlussblock der Methode "disneyViewControllerAnimated", in dem Sie für ViewController B erneut "abitViewControllerAnimated" aufrufen können. – iamyogish

+0

@iamyogish; Ich habe die Fragen bearbeitet, es funktioniert nicht wie vorgeschlagen. Kannst du sehen, ob ich etwas falsch mache – Nitya

Antwort

0

können Sie von C etwas tun, wie,

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 

oder

[self dismissViewControllerAnimated:YES completion:^{ /* do something when the animation is completed */ }]; 
[self.parentViewController dismissViewControllerAnimated:YES completion:^{ /* do something when the animation is completed */ }]; 

-Update per Kommentar:

Ersetzen Sie Ihre

[self dismissViewControllerAnimated:YES completion:^(){ 

    [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:^(){; 
     BCDThankYouViewController *thankuView=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ThankyouView"]; 
     [[self topViewController ]presentViewController:thankuView animated:YES completion:nil]; 
    }]; 
}]; 

mit

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 

//you can do something here in completion instead of nil. 

, wenn Sie drei Viewcontroller dissmiss wollen, dann können Sie self.presentingViewController.presentingViewController.presentingViewController verwenden.

Hoffnung, das wird helfen :)

+0

@ Lion: ich habe unten Methode in Viewcontroller C, die C ablehnt und hier habe ich den Code wie in Ihrem Kommentar hinzugefügt. Aber es nicht Controller B. Entschuldigen Sie bitte dies? Ich habe die Frage bearbeitet – Nitya

+0

überprüfen Update in Antwort – Lion

0

Gefällt Ihnen dieses Entlassen

//remove 
    [self removeFromParentViewController]; 
    [self didMoveToParentViewController:nil]; 
    [self.view removeFromSuperview]; 
0

Vielen Dank allen für Anregungen. Ich löste dieses Problem mit Hilfe von anderen SO-Posts. Hier ist Lösung

-(void)dismissModalStack { 
    UIViewController *vc = self.presentingViewController; 
    while (vc.presentingViewController) { 
     vc = vc.presentingViewController; 
    } 

    NSLog(@"Dismissing the view controller at root of view hiearchy: %@", [vc class]); 

    [vc dismissViewControllerAnimated:YES completion:^() { 
     BCDThankYouViewController *thankuView=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ThankyouView"]; 
     [[self topViewController ]presentViewController:thankuView animated:YES completion:nil]; 
    }]; 
} 
Verwandte Themen