iOS-多级presentViewController直接返回一级界面

转自:
http://www.cnblogs.com/yingkong1987/p/3343937.html

当遇到:

A presentViewController B , B presentViewController C, C presentViewController D,问如何从D一下子回到A,麻烦一点的办法就是一级一级的dismiss。

下面来说说我的办法:

首先,实现 BaseViewController 作为所有视图控制器的基类,然后在基类中实现返回最下层viewController的办法(注意:最底层是UIViewController,所有BaseViewController都放在其上边!):

- (void) turnToGame

{



UIViewController *viewController = self;

    while (viewController.presentingViewController)

    {

        if ([viewController isMemberOfClass:[BaseViewController class]])  // 直到找到最底层为止

        {

            viewController = viewController.presentingViewController;

        }

        else

        {

            break;

        }

    }



    if([[[UIDevicecurrentDevice]systemVersion]floatValue] >=6)

    {

        if (viewController)

        {

            [viewController dismissViewControllerAnimated:YEScompletion:nil];

        }

    }

    else

    {

        if (viewController)

        {

            [viewController dismissModalViewControllerAnimated:YES];

        }

    }

}

你可能感兴趣的:(ios,界面)