How to reject two or more rejectModalViewController controls?

I need to reject two modal view controllers, I know how to expose two or more view controllers

        UINavigationController* navController = self.navigationController;
    NSArray *array=[navController viewControllers];
    UIViewController* controller = [navController.viewControllers objectAtIndex:0];
    [navController popToViiewController:controller animated:YES];

Here's how I can go back to my first view, but if there are two or more deviations from the modal view, then how can I go back

Please help me, thanks Madan Mohan

+5
source share
5 answers
UINavigationController* navController = self.navigationController;
NSArray *viewControllers=[navController viewControllers];
UIViewController* controller = [viewControllers objectAtIndex:0];
[navController popToViewController:controller animated:YES];

if you set the object with index 0 in the above code, it will take you to the first view, which is the view controller.

1) Rootview --- > moodalview1 --- > moodalview2 --- > moodalview3, , .

2) Rootview --- > Pushview1 ---- > moodalview1 --- > moodalview2 ----- > moodalview3. , PushView.

+2

-[UIViewController dismissModalViewController]:

, , , . , ; . , , .

+5

[[[self presentingViewController] presentingViewController]  dismissModalViewControllerAnimated:YES];
+4
source

I use the following static utility method to model popToRootViewController for the modal stack:

// Util.m
+ (void)popModalsToRootFrom:(UIViewController*)aVc {
    if(aVc.parentViewController == nil) {
        return;
    }
    else {
        [Util popModalsToRootFrom:aVc.parentViewController];  // recursive call to this method
        [aVc.parentViewController dismissModalViewControllerAnimated:NO];
    }
}

You use it as follows:

[Util popModalsToRootFrom:aViewController];

If you want something more advanced, you can do this:

+ (void)popModalsFrom:(UIViewController*)aVc popCount:(int)count {
    if(aVc.parentViewController == nil || count == 0) {
        return;
    }
    else {
        [Util popModalsFrom:aVc.parentViewController popCount:count-1];  // recursive call to this method
        [aVc.parentViewController dismissModalViewControllerAnimated:NO];
    }
}

Then pass in the number of modals you need to place, or just -1 to completely fill the root.

+3
source

For iOS 5support animation== YES(views will be hidden in sequence) and completionblock:

+ (void)dismissAllVCsForVC:(UIViewController *)VC animated:(BOOL)animated completion:(BPSimpleBlock)completion {
    if (VC.presentedViewController == nil) {
        if (completion) {
            completion();
        }
    } else {
        [BaseViewController dismissAllVCsForVC:VC.presentedViewController
                                        animated:animated
                                      completion:
         ^{
             [VC dismissViewControllerAnimated:animated completion:completion];
         }];
     }
}
+1
source

All Articles