簡體   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