iOS 推出指定的UIViewController

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

November 19, 2019 · 1 min · holdsky