Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Eilon Krauthammer
4,768 Pointsjump to a different vew controller on demand
Hello, in my project I have a "sign in" view controller and my root view controller. I want that whenever the user isn't logged in the view will jump to the sign in view controller by a modal segue. I know how to do everything apart from the function to move to the sign in view controller in the viewDidLoad. How do I do that? thanks
1 Answer
Stone Preston
42,016 Pointsin viewDidLoad you will need to check to see if the user is logged in by checking to see if the currentUser variable is not nil. if they are not logged in, call the performSegueWithIdentifier method. make sure your segue is set up as manual segue from your root view controller ro your login view controller in your storyboard
//in your root view controller
- (void)viewDidLoad {
[super viewDidLoad];
PFUser *currentUser = [PFUser currentUser];
//user is not logged in
if (!currentUser) {
[self performSegueWithIdentifier:@"showLogin" sender:self];
}
see 05:59 of this video for more info. it shows how to do exactly what you want
Eilon Krauthammer
4,768 PointsEilon Krauthammer
4,768 PointsThanks!