PFLoginViewController How to switch between login screen and main page? Swift

587 views Asked by At

I am trying to use the PFLoginViewController to create a simple login screen for my app. The problem I am running into is the ability to switch between the login screen and the main page of the app based on .currentUser() output.

I was able to accomplish this in Objective C using this method:

AppDelegate.m

enter image description here enter image description here

LogInViewController.m

enter image description here

enter image description here

I'm using Swift in my new app and am trying to duplicate the method I used in Objective C but I'm getting this error and the simulator is all black.]

enter image description here

Here's what my code looks like in swift.

AppDelegate

enter image description here

LoginVC

enter image description here

I have done some looking into this and I've seen that it's an issue with viewDidLoad instead of using viewWillAppear but I don't see the application to my issue because it worked in Objective C in the didFinishLaunchingWithOptions and also the delegate methods of PFLoginViewController aren't called in viewDidLoad.

Any clues as to what's my big mistake?

2

There are 2 answers

2
Wain On

In the Obj-C you're getting the navigation controller from the window (the root view controller), so it's presented. In the swift you're creating a new navigation controller, and then you might again create another new navigation controller with a root view controller. Neither of these are presented so trying to use them for much other than presenting them won't work. This is a significant logical change between the 2 code samples. There is nothing to stop you following the same approach in each language and it should resolve your error.

0
Wesley Cho On

I fixed the issue I was having.

AppDelegate

enter image description here

Instead of presentViewController I used pushViewController

enter image description here