繁体   English   中英

如何在不导入第一个UIViewController类的情况下从UINavigationController中的另一个UIViewController手动取消分配UIViewController?

[英]How can I dealloc manually UIViewController from another UIViewController in UINavigationController without import the first UIViewController class?

我有一个navigationController。 第一个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。 有办法吗?

创建一个新的第一个视图控制器

FirstViewController * first = [[FirstViewController alloc] init];

重置导航堆栈

[self.navigationController setViewControllers:@ [first,self] animation:NO];

导航到第一个

[self.navigationController popViewController:YES];

您将需要在导航控制器中重置视图控制器阵列。

在第二个视图控制器中:

[self.navigationController setViewControllers:@[self] animated:NO];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM