基于逻辑思考swift

时间:2015-07-08 10:05:26

标签: ios swift segue

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

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

2 个答案:

答案 0 :(得分:3)

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

int self.rssiBuffer[1000]; // I assume we have buffer like that
self.rssiBuffer[self.bufferIndex++] = rssi

<强>更新

您可以在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

希望它会对你有所帮助。

答案 1 :(得分:1)

在你的appDelegate&#34; didFinishLaunchingWithOptions&#34;在返回之前

 var userSignedUp = NSUserDefaults.standardUserDefaults().boolForKey("signup")

        if userSignedUp {
               // have to show another view
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewControllerWithIdentifier("anyOtherViewThanSignUp") as! TViewController
        self.window?.rootViewController =  vc
        } else {
             // have to show SignUp view
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewControllerWithIdentifier("signupView") as! SViewController
        self.window?.rootViewController =  vc

        }
    }