简体   繁体   中英

navigation ios 8 swift?

I am new to the IOS world. I having trouble changing view when im switching to a new view which only can be shown when I login. I am using inside the loginfuction:

@IBAction func loginVerification(sender: UIButton!) {
        //Check with the cloud
        //temporary faking credentials

        var user = "n"
        var pass = "n"

        if usernameLogin.text == user &&
            passwordLogin.text == pass
        {
            println("Correct credentials")
            let homeviewcontroller = HomeViewController()

            self.presentViewController(homeviewcontroller, animated: true, completion: nil)


        }
        else
        {
            println("Wrong credentials!!")
        }
}

The function above is triggered when I press the login button which checks for credentials. Using the lines above makes the view black. Any suggestions on how to make it work? Any tutorial I can follow on navigation between views? And please don't be so hard on me :)

Thanks in advance!

Hi I would try the Apple tutorials - they are fairly well written and have code samples. Here is one that I used when I was learning: https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/SecondTutorial.html . This one is specifically about navigating using Storyboards and Segues. If you look on the left of the page, you'll see links to other tutorials that may be helpful for you when getting started.

Try the following code:

let controller: homeviewcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("homeviewcontroller") as! homeviewcontroller
            self.presentViewController(controller, animated: true, completion: nil) 

       @IBAction func loginVerification(sender: UIButton!) {
        //Check with the cloud
        //temporary faking credentials

        var user = "n"
        var pass = "n"

        if usernameLogin.text == user &&
            passwordLogin.text == pass
        {
            println("Correct credentials")

let controller: homeviewcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("homeviewcontroller") as! homeviewcontroller
            self.presentViewController(controller, animated: true, completion: nil)
        }
        else
        {
            println("Wrong credentials!!")
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM