我想在应用程序首次启动时根据 if 语句快速显示两个视图之一,我该怎么做
这就是逻辑
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)
}
}
Update:
您可以在您的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
}
希望它能帮助你。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)