0

У меня есть контроллер вида A, который имеет табличный вид и основан на выборе строки, я буду открывать другой контроллер вида B по модулю. У меня также есть таймер бездействия, реализованный для моего приложения. Теперь, когда B представлен и A представляет контроллер, и из-за неактивности пользователя, другой контроллер контроля неактивности View C будет открыт по модулю поверх B. Это означает, что у меня есть A, затем B поверх A и C сверху B. Теперь пользователь нажал кнопку из C, чтобы выполнить выход, и я могу отклонить только C. Но View Controller B никогда не отклоняется.Как отклонить контроллер модального представления, если имеется несколько контроллеров представления

Неактивность реализована с использованием события касания и уведомлений, а уведомление представляет собой неактивный контроль над моделями поверх текущего представления, как указано в приведенном ниже коде.

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

Есть ли способ, которым я могу отменить диспетчер B также?

In View Controller C method, где я отклоняю контроллер просмотра C, я редактирую код в соответствии с предложением, но View Controller B по-прежнему не отклоняется.

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

Поскольку вы используете NavigationController, вы можете использовать 'unind' segue. См. Ответ [здесь] (http://stackoverflow.com/a/17607083/2535467). – CaptJak

+0

Используйте блок завершения метода rejectViewControllerAnimated, в котором вы можете снова вызвать rejectViewControllerAnimated для ViewController B. – iamyogish

+0

@iamyogish; Я редактировал вопросы, не работая в соответствии с предложением. Вы видите, что я делаю что-то неправильно – Nitya

ответ

0

вы можете сделать из C что-то подобное,

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

или

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

Update как за комментарий:

Заменить

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

с

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

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

если вы хотите dissmiss три ViewController, то вы можете использовать self.presentingViewController.presentingViewController.presentingViewController.

надеюсь, что это поможет :)

+0

@ Lion: у меня есть метод ниже в Viewcontroller C, который отклоняет C, и здесь я добавил код в соответствии с вашим комментарием. Но его не отклоняет контроллер B. Можете ли вы посмотреть на это? Я отредактировал вопрос – Nitya

+0

проверить обновление в ответе – Lion

0

Отклонить Как это

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

Спасибо всем за советы. Я решил эту проблему с помощью других сообщений SO.Here является решением

-(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]; 
    }]; 
} 
Смежные вопросы

 Смежные вопросы