ios - 如何在 swift 中显示一次 UIVIewController

标签 ios swift

我正在制作一个应用程序,我只需要显示一次登机 View Controller ,所以当用户重新进入应用程序时,登机 View Controller 不会再出现。

最佳答案

我猜登机 View Controller 是您的初始 View Controller 。在应用程序委托(delegate)中试试这个

首先将 checkFunction() 放在 didFinishLaunchingWithOptions 中,然后为您要访问的 View Controller 设置标识(例如 Home)

func checkFunction() {
    let acceptedTerms = UserDefaults.standard.string(forKey: "acceptedTerms")
    if acceptedTerms != nil && acceptedTerms == "Yes" {
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let VC = storyBoard.instantiateViewController(withIdentifier: "Home")
        self.window?.rootViewController = VC
    }
}

其次,修改某处的UserDefaults.standard.string

// example
@IBAction func acceptButtonTapped(_ sender: AnyObject) {
    UserDefaults.standard.set("Yes", forKey: "acceptedTerms")
    UserDefaults.standard.synchronize()
}

关于ios - 如何在 swift 中显示一次 UIVIewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47064646/

相关文章:

ios - 如何在 Swift 中显示文档目录中的贴纸

android - iOS/Android 与 Delphi/C# 桌面应用程序同步

objective-c - 核心剧情: Two plots sharing the same x axis

swift - FileManager 抛出什么错误?

swift - 以编程方式访问 UIViewController 子类中 UIView 子类的成员

ios - scichart中的x轴位置

ios - 在登录成功时运行函数 MGTwitterEngine ala FBConnect

ios - 呈现新的 View Controller 。选项卡式图标消失

swift - 在 watchOS 中使用 environmentObject

ios - 无法在 Swift 3 中使用闭包语法