2017-10-05 86 views
0

我使用標籤欄控制器從VC1轉到VC2。這樣做,VC1停留在內存中。我使用VC2管理數據,當我回到VC1(使用標籤欄控制器)時,我使用viewWillAppear中的函數重新加載VC1,但它的工作正常,但在重新加載動畫期間,VC1的先前版本仍然可見。如何在使用標籤欄控制器離開視圖時忽略視圖

我必須在動畫或重新加載過程開始之前關閉VC1(從內存中)。
我試過了,在viewWillAppear,和viewDidDisappear的VC1這些命令都沒有成功。

self.dismiss(animated: true, completion: nil) 
self.presentedViewController?.dismiss(animated: true, completion: nil) 

我的猜測是,最好的辦法是解散VC1時,移動到VC2,但沒有找到方法。

感謝您的幫助。

+0

觀察者很明顯,在你的VC1的意見需要從VC2模式改變後,被「刷新」。如果您可以分享您在VC1中擁有什麼樣的觀點,將有助於更多。 –

回答

0

我的建議是,使用NotificationCenter在VC1中添加觀察者,如果發生某些事件,則從VC2中觸發。

添加觀察者。

NotificationCenter.default.addObserver(forName: Notification.Name(rawValue: "updateVC1"), 
             object:nil, queue:nil) { 
             notification in 

             // do something 
} 

觸發信號VC2

NotificationCenter.default.post(name: Notification.Name(rawValue: "updateVC1"), object: nil) 
相關問題