I have a view controller A which has table view and based on row selection, i will open another view controller B modally. I also have inactivity timer implemented for my application. Now when B is presented and A is presenting controller and due to user’s inactivity, another view controller Inactivity View Controller C will be opened modally on top of B. That means i have A , then B on top of A , and C on top of B. Now, user has clicked a button from C to do logout and i am able to dismiss only C. But View Controller B is never dismissed.
Inactivity is implemented using touch event and notifications and notification is presenting inactivityviewcontroller modally on top of current view as mentioned in below code.
- (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];
}
Is there any way i can dismiss controller B also?
In View Controller C method where i m dismissing view controller C, i edit the code as per suggestion, But View Controller B is still not dismissed.
- (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];
// }];
}