基于逻辑的SWIFT分段 [英] Segue in swift based on a logic
本文介绍了基于逻辑的SWIFT分段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
if signupconfirmed == true {
// have to show one view
} else {
// have to show another view
}
推荐答案
一种方法是,您可以使用以下代码的标识符来初始化视图控制器:
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
}
希望它能对您有所帮助。
这篇关于基于逻辑的SWIFT分段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文