How to dismiss the two or more dismissModalViewController?

后端 未结 5 1164
孤城傲影
孤城傲影 2020-12-19 11:26

I need to dismiss the two modal view controllers, I know how to pop two or more view controllers

        UINavigationController* navController = self.navigat         


        
5条回答
  •  一个人的身影
    2020-12-19 12:06

    I use the following utility static method to simulate popToRootViewController for a stack of modals:

    // 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 like this:

    [Util popModalsToRootFrom:aViewController];
    

    If you want something more advanced, you could 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 the number of modals to pop, or just -1 to pop all the way to the root.

提交回复
热议问题