1

I am working on a tutorial I found online with Parse. In the video, they use the parse login, if the user is not logged in, it automatically pops up the parse login, and then you are able to sign in and sign up.

Parse is a database to store information. (Just thought this should be noted)

I have created both the custom login, and signup, and linked with parse, so when I check online in the database, the users appear in there. Now I want to redirect the users after they have logged in, or signed up, but I'm having trouble with that.

In the video, they use these lines to use the parse log in:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    if (PFUser.currentUser() == nil){
        var loginViewController = PFLoginViewController()
        loginViewController.delegate = self

        var signUpViewController = PFSignUpViewController()
        signUpViewController.delegate = self

        loginViewController.signUpViewController = signUpViewController

        self.presentViewController(loginViewController, animated: true, completion: nil)
    }
}

So I tried that, and tried to modify it to work with my custom login, but I cannot get it to work, the screen just goes black.

I just want to note that: I have 2 navigation controllers. 1 for the login/signup and another for the home screen of the app.

The classes that I'm using are: ViewController (main screen) where you can choose whether to login, or signup, and this is the screen I would like to redirect if user is not logged in. This class has two buttons, login and sign up.

CustomViewLoginViewController that is the screen it goes after you press the login button.

CustomSignUpViewController that is the screen it goes after you press the signup button.

So basically if the user is not logged in, pop the ViewController so that the user has the option to login or sign up, and whether they sign up, or log in, go back to home screen.

Any help would be great.

Here's my part of my login class:

        if (user != nil) {
            self.dismissViewControllerAnimated(true, completion: nil)
            var alert = UIAlertView(title: "Success", message: "Signed in succesfully!", delegate: self, cancelButtonTitle: "Continue")
            alert.show()

        } else {
            var alert = UIAlertView(title: "Error", message: "\(error)", delegate: self, cancelButtonTitle: "Ok")
            alert.show()
        }

Edit: I managed to go back to the home screen after logging in by using:

let homeScreen = self.storyboard!.instantiateViewControllerWithIdentifier("homeScreen") as! TimelineTableViewController

self.navigationController!.pushViewController(homeScreen, animated: true)

but now it doesn't completely load the Home screen, and my Xcode says it cannot update missing constraints /:

2 Answers 2

1

I would suggest an alternate approach.

Make your 'Home' view controller the initial view controller.

In viewWillAppear check if PFUser.currentUser == nil, if it does then navigate to your login/signup view controller. After the user logs in simply pop or dismiss the login or signup view controller.

Updated: Initial View Controller:

override func viewWillAppear(animated: Bool) {

    if PFUser.currentUser() != nil {

        // Load your data or do what you do...
    } else {

        performSegueWithIdentifier("yourStoryboardSegue", sender: self)
    }
}

If that segue defined in your storyboard is a modal then dismiss it after a user signs up or logs in:

self.dismissViewControllerAnimated(true, completion: nil)

Or if that segue defined in your storyboard is adding the view controller to your UINavigationController stack (where you'd be able to use a Back button)

self.navigationController?.popViewControllerAnimated(true)

Update for dismissing the signup / login view controller:

if (user != nil) {

    dispatch_async(dispatch_get_main_queue(), { () -> Void in

        self.dismissViewControllerAnimated(true, completion: nil)
    })

}

Since you're processing the login in a background thread you need to send your UI updates to the main queue for processing.

Sign up to request clarification or add additional context in comments.

1 Comment

Okay so I tried that, and it didn't go back. It still stayed in the login screen. When I used self.navigationController?.popViewControllerAnimated(true) it went back, but to the screen that asks you if you want to sign up or login.
0
else {

  performSegueWithIdentifier("ur segue identifier", sender: nil)

}

or i think i couldn't understand your problem .

2 Comments

I believe this is to give direction to the SignUp/LoginButton to redirect to the home screen. I have my 'Home' view controller, like the home screen as my startUp controller, so if the user is not logged in, it automatically will redirect you to the signUp/Login screen, but I cannot get it to work.
override func viewWillAppear(animated: Bool) { if (PFUser.currentUser() == nil){ var loginViewController = ViewController() self.presentViewController(loginViewController, animated: true, completion: nil) } } that's what I'm using. It redirects to the screen, but it's all black, so I'm guessing I'm missing something

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.