2015-11-03 53 views
0

我使用賽格瑞導航與類型show segues.I的self.perfomSegueWithIndentifier功能發現後,每導航等視圖/視圖 - 控制並沒有從RAM.What刪除我必須這樣做來解決這個移除View

+0

你是否說你的視圖控制器對象保留,即使你解僱視圖控制器?如果是這樣,檢查是否有一些保留週期。 – Abhinav

+0

我認爲他一次又一次地在導航棧中推送視圖控制器,這會消耗越來越多的內存。在執行segue之前,您可以在導航控制器上使用「popToRootViewController」。 – ryancrunchi

+0

yes,exactly.Lets say我必須按鈕1 - 導航到第二個viewcontroller 2 - 導航到第一個視圖控制器,並且我想在導航後刪除先前的viewcontroller –

回答

1

編程

比方說你有VC1嵌入在UINavigationController現在VC1成爲導航堆棧的頂部視圖控制器。

所以,如果你打算VC1 -> VC2

self.navigationController?.pushViewController(vc2, animated: true)

在這種情況下VC2成爲導航堆棧的頂部視圖控制器。

和,同時從VC2 -> VC1回來(按鈕抽頭上VC2執行此語句)

self.navigationController?.popViewControllerAnimated(true)

在那種情況下再次VC1成爲導航堆棧上的頂視圖控制器。

使用Segue公司

只需使用Show(e.g Push)並設置標識符,像我有pushView 並調用

self.performSegueWithIdentifier("pushView", sender: nil)移動VC1 -> VC2

和回來VC2 -> VC1

使用相同的self.navigationController?.popViewControllerAnimated(true)

enter image description here

+0

你不使用segues我是嗎?我不''UINavigationController'.I有簡單的viewControllers與segue導航 –

+0

是的,但現在我也爲此添加了示例。 – Buntylm

+0

如果我導航到vc2和vc3之後,在這種情況下它是否會從內存中刪除vc1? –

1

這是你在找什麼:

開按鈕輕按 - 視圖 - 控制器1:

self.navigationController.pushViewController(secondViewController, animated: true) 

開按鈕輕按 - 視圖 - 控制器2:

self.navigationController?.popViewControllerAnimated(true) 
+0

好吧,我會試試這個 –

+0

如果您正在採用segue方式,請正確實施'unwind'。看看這個[博客](http://spin.atomicobject.com/2014/10/25/ios-unwind-segues/)。 – Abhinav

+0

請閱讀我的意見到另一個答案,你能解釋我如何在導航時從RAM中刪除視圖 –