我有一个导航 Controller 。第一个viewcontroller 是FirstViewController 的一种。当我在 FirstViewController 中点击一个按钮时,它会将第二个 viewController 插入 navigationController,它是一种 SecondViewController 类。当我点击 SecondViewController 中的按钮时,我想释放 FirstViewController(之前保存在 navigationController 中)以便重新开始,就好像我第一次在 SecondViewController 的 navigationItem 中点击返回按钮时打开 FirstViewController。这里是当我点击 secondViewController 中的按钮时调用的方法的代码:
NSArray * navigationPath = [self.navigationController viewControllers];
UIViewController *previousVC = [navigationPath objectAtIndex:[navigationPath count]-2];
[previousVC performSelector:@selector(viewDidUnload)];
它不会释放 FirstViewController。有办法吗?
最佳答案
创建一个新的第一个 View Controller
FirstViewController *first = [[FirstViewController alloc]init];
重置导航堆栈
[self.navigationController setViewControllers:@[first, self] animated:NO];
导航到第一个
[self.navigationController popViewController:YES];
关于ios - 如何在不导入第一个 UIViewController 类的情况下从 UINavigationController 中的另一个 UIViewController 手动释放 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25742661/