我有一个应用程序与滑块,我提供了下拉菜单切换用户。只要应用程序用户切换到其他用户,我想重置整个导航流程,并从第一个屏幕开始。
例如
屏幕A -〉屏幕B -〉屏幕C -〉屏幕D -〉用户打开滑块并切换用户-〉跳转到屏幕A(从导航中删除其他屏幕)。我们可以考虑gmail应用程序的例子在这里,我们可以在不同的帐户和gmail应用程序之间切换重定向用户到主收件箱。
编辑:
我正在使用git上的滑块菜单库。
https://github.com/dekatotoro/SlideMenuControllerSwift
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var navigationController: UINavigationController?
var storyboard: UIStoryboard?
var leftViewController: LeftSidePanelViewController?
// var uuid: String?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if Utility.getUserStatus() == 0 {
storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainViewController = storyboard!.instantiateViewControllerWithIdentifier("LoginViewController") as! LoginViewController
leftViewController = storyboard!.instantiateViewControllerWithIdentifier("LeftSidePanelViewController") as? LeftSidePanelViewController
navigationController = UINavigationController(rootViewController: mainViewController)
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
leftViewController!.mainViewController = navigationController
let slideMenuController = ExSlideMenuController(mainViewController:navigationController!, leftMenuViewController: leftViewController!)
slideMenuController.automaticallyAdjustsScrollViewInsets = true
slideMenuController.delegate = mainViewController
self.window?.backgroundColor = UIColor(red: 236.0, green: 238.0, blue: 241.0, alpha: 1.0)
self.window?.rootViewController = slideMenuController
self.window?.makeKeyAndVisible()
Utility.setUUID(UIDevice.currentDevice().identifierForVendor!.UUIDString)
} else {
storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainViewController = storyboard!.instantiateViewControllerWithIdentifier("HomeViewController") as! HomeViewController
leftViewController = storyboard!.instantiateViewControllerWithIdentifier("LeftSidePanelViewController") as? LeftSidePanelViewController
navigationController = UINavigationController(rootViewController: mainViewController)
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
leftViewController!.mainViewController = navigationController
let slideMenuController = ExSlideMenuController(mainViewController:navigationController!, leftMenuViewController: leftViewController!)
slideMenuController.automaticallyAdjustsScrollViewInsets = true
slideMenuController.delegate = mainViewController
self.window?.backgroundColor = UIColor(red: 236.0, green: 238.0, blue: 241.0, alpha: 1.0)
self.window?.rootViewController = slideMenuController
self.window?.makeKeyAndVisible()
}
return true
}
}
我已经尝试了不同的解决方案,但似乎没有任何工作。
var alreadyPushed = false
//Check if the view was already pushed
if let viewControllers = self.navigationController?.viewControllers {
for viewController in viewControllers {
if let viewController = viewController as? HomeViewController {
self.navigationController?.popToViewController(viewController, animated: true);
print(" Push Your Controller")
alreadyPushed = true
break
}
}
}
if alreadyPushed == false {
print("Pushing...")
let YourControllerObject = self.storyboard?.instantiateViewControllerWithIdentifier("HomeViewController") as! HomeViewController
self.navigationController?.presentViewController(YourControllerObject, animated: true, completion: nil)
// HERE also tried pushViewController but that was also not working..
self.navigationController?.dismissViewControllerAnimated(false, completion: nil)
}
解决方案二:
还尝试了self.navigationController?.viewController.removeAll(),然后推送/呈现HomeView,但也无法正常工作。
任何人有任何建议或提示来解决这个问题。
4条答案
按热度按时间e4yzc0pl1#
答得极快道:
您将擦除视图控制器堆栈并重置导航。
3lxsmp7m2#
你可以为它使用
或者用导航栈做些修改
ergxz8rk3#
而不是恢复导航,为什么不可以设置rootViewController窗口再次像下面这样?
vvppvyoh4#
对于Swift 3,请使用以下代码:
自定义导航控制器弹出到根视图控制器(动画:正确)