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

iOS Build a Self-Destructing Message iPhone App Using Parse.com as a Backend and Adding Users Logging In and Logging Out

Ravin Kohli
Ravin Kohli
3,367 Points

not popping to root view controller

whenever i press login or sign up the navigation stack is not popping to the root view controller i checked by putting log statements and it was entering the else block where it is supposed to pop to the root controller also on the login and the sign up screen there is not navigation bar as well

LoginViewController.m
  • (IBAction)login:(id)sender{ NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; NSString *password = [self.passwordField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; if (([username length] == 0)||([password length] == 0)) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"OOPS!!" message:@"Enter valid entries" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];

    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
    

    } else{ [PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError *error) { if (user) { [self.navigationController popToRootViewControllerAnimated:YES]; } else { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"OOPS!! Something went wrong" message:[error userInfo][@"error"] preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];

                                              [alert addAction:defaultAction];
                                              [self presentViewController:alert animated:YES completion:nil];
    
                                          }}];
    

    } }

1 Answer

Ravin, here is a full template for the social network application: Click Here.