我面临两个问题;
如何呈现登录屏幕始终意味着即使应用程序来自后台,我也需要显示登录页面。
我在 Home Controller 中有一个注销按钮,我使用 Show Segue 从登录状态转到了主页状态,但是我无法在单击注销时返回到登录状态。 我使用下面的代码移动到登录页面
self.navigationController?.popViewControllerAnimated(true)
最佳答案
您的登录页面不在导航 Controller 内。您的导航 Controller 无法弹出。相反,我们需要关闭导航 Controller 本身。
self.navigationController?.dismissViewControllerAnimated(false, completion: nil)
因此,只要您想返回到第一个登录页面,就可以随时调用此代码。当应用程序从后台返回时执行此操作时,点击应用程序委托(delegate)的 applicationWillEnterForeground(application:)
方法。
鉴于我们可能不会从应用程序委托(delegate)中引用导航 Controller 或我们的任何 View Controller ,我们可以改为让应用程序委托(delegate)的窗口的 Root View Controller (应该是您的登录 Controller )关闭所有内容.所以在 applicationWillEnterForeground(application:)
中添加:
self.window?.rootViewController?.dismissViewControllerAnimated(false, completion: nil)
关于iOS Swift 始终以相同的 View Controller 开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31430357/