ios - 如何在不导入第一个 UIViewController 类的情况下从 UINavigationController 中的另一个 UIViewController 手动释放 UIViewController?

标签 ios objective-c uiviewcontroller uinavigationcontroller dealloc

我有一个导航 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/

相关文章:

ios - 为什么BackgroundTasks中的异步/长时间运行操作不起作用?

objective-c - 实现后台 worker - Obj C/Cocoa

iphone - 做 git status, objective c, git 时总是得到 Crashlytics is modified

ios - 实现照片浏览器 View

ios - ViewController 正在加载一个不存在的 Nib

iphone - 如何在 GUI 级别管理启动问题?

ios - 由于 Firebase GoogleService-Info.plist,Codemagic iOS 构建失败

ios - 你如何创建一个对象的 NSMutableArray,它不会增加添加到它的每个对象的保留计数?

ios - 自定义过渡 iOS(推送/弹出)

ios - 如何在 Objective-C 中检查一个对象是否为 nil?