编程技术记录

世界你好!

UINavigationController提供的常用接口是push和pop,但都是操作最顶层的页面topViewController,若要操作指定的页面,可以访问属性viewControllers


@implementation UINavigationController(zlAddition)

- (void)zl_popTheViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (viewController.navigationController == self)
    {
        if (self.topViewController == viewController)
        {
            [self popViewControllerAnimated:animated];
        }
        else
        {
            NSMutableArray *arr = [self.viewControllers mutableCopy];
            if (arr.lastObject != viewController)
            {
                [arr removeObject:viewController];
                [self setViewControllers:arr animated:animated];
            }
        }
    }
}

@end

发表回复

© Beli. All Rights Reserved.