gpt4 book ai didi

ios - 基于逻辑快速进行Segue

转载 作者:搜寻专家 更新时间:2023-10-31 22:15:14 24 4
gpt4 key购买 nike

我想在应用程序首次启动时基于 if 语句在 swift 中显示两个 View 之一,我该怎么做这是逻辑

if signupconfirmed == true {
// have to show one view
} else {
// have to show another view
}

最佳答案

一种方法是您可以使用以下代码启动带有标识符的 viewController:

var signupconfirmed = true
@IBAction func signUpPressed(sender: AnyObject) {

if signupconfirmed {
// have to show one view
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("First") as! SViewController
self.presentViewController(vc, animated: true, completion: nil)
} else {
// have to show another view
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("Second") as! TViewController
self.presentViewController(vc, animated: true, completion: nil)
}
}

更新:

您可以在您的 AppDelegate.swift 中执行此操作

这是您的代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

let signupconfirmed = NSUserDefaults.standardUserDefaults().boolForKey("SignUp")
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var initialViewController = UIViewController()
var storyboard = UIStoryboard(name: "Main", bundle: nil)
if signupconfirmed {
initialViewController = storyboard.instantiateViewControllerWithIdentifier("First") as! UIViewController
} else{
initialViewController = storyboard.instantiateViewControllerWithIdentifier("Second") as! UIViewController
}

self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
return true
}

希望对你有所帮助。

关于ios - 基于逻辑快速进行Segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31289462/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com