我有一個標籤欄應用程序與導航控制器在應用程序的5個選項卡中的4個。我在我的應用程序中有一個「重置應用程序」功能,可以清除所有數據等......我也希望將所有視圖控制器彈回到其頂視圖。我知道如何使用popToRootViewControllerAnimated爲單個導航控制器彈出到根目錄,但可以彈出每個選項卡上的所有視圖控制器嗎?在標籤欄上彈出所有視圖控制器應用程序
3
A
回答
10
您需要通過viewControllers陣列tabBarController &流行到根視圖控制器枚舉如果控制器陣列的UINavigationController喜歡 -
for(UIViewController *viewController in tabBarController.viewControllers)
{
if([viewController isKindOfClass:[UINavigationController class]])
[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
}
0
你有另一種選擇是使用NSNotifications。我需要在關閉模式視圖(定時器上的幻燈片放映)時在我的所有選項卡上觸發popToRootViewController,並且這是我能夠弄清楚如何執行此操作的唯一方法。 我在模態視圖的viewWillDissapear方法中觸發了NSNotification,然後在我希望關閉的每個視圖中對其進行響應。
1
拉胡爾的答案是完美的解決方案。但是如果你的標籤欄有超過5個標籤,你會看到「更多」標籤。你需要顯式重置這個選項卡(只需將tabBarController.moreNavigationController彈出到rootViewController)。
這裏是代碼示例:
for(UIViewController *viewController in tabBarController.viewControllers)
{
if([viewController isKindOfClass:[UINavigationController class]])
[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
}
[tabBarController.moreNavigationController popToRootViewControllerAnimated:NO];
0
func popAll(){
let tabBarController = window!.rootViewController as! UITabBarController
tabBarController.delegate = self
if let tabBarViewControllers = tabBarController.viewControllers {
let campusController = tabBarViewControllers[0] as! UINavigationController
let campusTVC = campusController.viewControllers[0] as! CampusTVC
_ = campusTVC.navigationController?.popToRootViewController(animated: false)
let adController = tabBarViewControllers[1] as! UINavigationController
let adminTVC = adminController.viewControllers[0] as! AdTVC
_ = adminTVC.navigationController?.popToRootViewController(animated: false)
let searchController = tabBarViewControllers[2] as! UINavigationController
let searchTVC = searchController.viewControllers[0] as! SearchTVC
_ = searchTVC.navigationController?.popToRootViewController(animated: false)
}
}
我的代碼在彈出斯威夫特所有選項卡實例。這是在我的應用程序委託。 這就是我在VC中的稱呼方式
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.popAll()
相關問題
- 1. 彈出視圖控制器後出現的標籤欄
- 2. 彈出並在標籤欄應用程序中推送視圖
- 3. 退出iPhone應用程序,從標籤欄控制器?
- 4. 應用程序在標籤欄視圖控制器內動作後崩潰
- 5. 旋轉視圖控制器不能在標籤欄中查看應用程序
- 6. 從標籤欄控制器中完全刪除所有視圖控制器
- 7. 訪問標籤欄視圖控制器
- 8. iPhone:視圖控制器的標籤欄
- 9. 使用標籤欄控制器添加登錄視圖到應用程序
- 10. 應用程序崩潰時彈出視圖控制器
- 11. 在標籤欄應用程序中使用導航控制器。
- 12. 從導航欄視圖控制器導航到標籤欄視圖控制器
- 13. 如何在iOS中的標籤欄控制器中從堆棧彈出視圖
- 14. 從標籤欄應用程序的UITableView推新的視圖控制器
- 15. 將實用程序應用程序(2個視圖控制器)轉換爲標籤欄應用程序
- 16. 在基於視圖的應用程序中同時使用導航控制器和標籤欄控制器
- 17. 在子視圖上隱藏標籤欄控制器
- 18. 如何在標籤欄控制器上顯示模態視圖?
- 19. 如何標籤欄控制器添加到拆分視圖控制器應用
- 20. 設備方向啓動標籤欄中的所有視圖控制器應用程序
- 21. 在標籤欄控制器/導航控制器上添加自定義視圖?
- 22. 故事板 - 視圖控制器到標籤欄控制器
- 23. 實例化視圖控制器Swift 3標籤欄控制器
- 24. 顯示視圖控制器之前標籤欄控制器
- 25. 從視圖控制器刪除標籤欄控制器
- 26. 從標籤欄控制器註銷到根視圖控制器
- 27. 標籤欄控制器與視圖控制器
- 28. 從視圖控制器移動到標籤欄控制器
- 29. 使用導航控制器添加視圖控制器到基於標籤欄的應用程序?
- 30. 使用視圖控制器既作爲模式視圖控制器和作爲標籤欄視圖控制器
你打我吧。 –
非常感謝! – Carl
雖然我得到'不平衡的調用開始/結束外觀轉換' - 任何想法來解決它? – Teffi