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];
// }];
}
Da Sie eine NavigationController verwenden, können Sie die "Abwicklungs" -Sequenz verwenden. Siehe Antwort [hier] (http://stackoverflow.com/a/17607083/2535467). – CaptJak
Verwenden Sie den Abschlussblock der Methode "disneyViewControllerAnimated", in dem Sie für ViewController B erneut "abitViewControllerAnimated" aufrufen können. – iamyogish
@iamyogish; Ich habe die Fragen bearbeitet, es funktioniert nicht wie vorgeschlagen. Kannst du sehen, ob ich etwas falsch mache – Nitya