【发布时间】:2015-10-28 16:08:13
【问题描述】:
在我的应用中,当用户登录时,我将帐户页面设置为新的根 VC。
看起来像这样:
导航控制器 -> 表格视图 -> menu(modal segue) -> 登录屏幕(modal segue) -> 帐户页面
当从登录转换到我正在使用的帐户时:
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let vc = storyboard.instantiateViewControllerWithIdentifier("testVc")
let navigationController = self.view.window?.rootViewController as! UINavigationController
navigationController.setViewControllers([vc], animated: true)
这使帐户页面成为新的根 VC。但唯一的问题是一旦显示菜单和登录表单仍然在屏幕上可见。
那么如何清除显示为模态的两个旧 VC?
更新使它可以使用:
@IBAction func loginButtonDidTouch(sender: AnyObject) {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("testVc")
let navigationController = self.view.window?.rootViewController as! UINavigationController
self.presentingViewController!.presentingViewController!.dismissViewControllerAnimated(false) { () -> Void in
navigationController.setViewControllers([vc], animated: true)
}
}
但我不知道这样做是否正确?
【问题讨论】:
标签: ios swift viewcontroller