2016-08-24 73 views
0

我有一個具有自己的根的多個(4)導航控制器的iOS應用程序。從所有堆棧中刪除所有控制器

結構爲:

NavController(根:登錄)

- > TabBarController(首頁) - (搜索) - (檔案)

------> NavController (根:首頁)

-------------> TableController

-----------------> DetailController

------> NavController(根:搜索)

------> NavController(根:檔案)(這裏註銷按鈕)

當我在上這些navigationcontrollers(即Profile),有一個註銷按鈕,應該帶我到初始登錄屏幕,我如何確保所有導航堆棧中的所有控制器在加載登錄之前已被刪除?

我已經試過poptorootviewcontroller但是這也只是個人資料頁

回答

0

可以使用NSNotificationCenter來處理這個問題。

當用戶註銷時,發佈本地通知到你的應用程序中使用:

NSNotificationCenter.defaultCenter().postNotificationName("kLogOut", object: self) 

然後,在每個選項卡的根視圖控制器,註冊偵聽該通知,並實施選擇器功能:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourViewController.logOutNotificationAction), name: "kLogOut", object: nil) 

func logOutNotificationAction() { 
    self.navigationController?.popToRootViewControllerAnimated(false) 
}