Reputation: 1413
In my login view controller, I have a check to see if user is logged in or not. If yes, I want them to be redirected via segue to profile page and if not then remain and login using their credentials.
The segue is not executing for some reason although I am sure that the currentUser is properly set and when tested with UIAlert it shows properly.
Below is code and commented out part is for the alert only
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var currentUser = PFUser.currentUser()
if currentUser != nil {
/*let alert = UIAlertView()
alert.title = "Welcome Back!"
alert.message = "You are logged in!"
alert.addButtonWithTitle("Ok")
alert.show()*/
self.performSegueWithIdentifier("showProfileSegue", sender: self)
} else {
let alert = UIAlertView()
alert.title = "Stranger"
alert.message = "You will be requested to enter your details"
alert.addButtonWithTitle("Ok")
alert.show()
}
}
I have a segue with identifier "showProfileSegue" setup between the two views.
Thanks
Upvotes: 0
Views: 44
Reputation: 2400
AFAIK viewDidLoad()
is not the right place in the view controller's lifecycle from which to push the segue. Because the initial view will not yet have appeared. Have you tried testing pushing it from viewDidAppear()
?
If you are certain that pushing the segue from a lifecycle method is the right way to achieve what you want. But bear in mind that some of the lifecycle methods can be called repeatedly. If the login screen appears only once per session then maybe that is okay.
It might be worth also testing that your segue and your prepareForSegue
is functioning as expected by pushing it from a test button.
Upvotes: 1