Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Vanessa Cantero Gómez
Vanessa Cantero Gómez
7,376 Points

Self-Destructing Message App

Hi guys!

I'm currently doing this app from scratch programmatically (without storyboards) and since it's my first app using navigationControllers, authentication, etc... I'm having troubles with transitions between views.

When the app shows up for the first time, the Inbox tab perform a segue (I really don't know if this is the correct way, but it works) to LogIn viewController if the user never has login previously. The code is:

- (void)viewDidLoad
{
    [super viewDidLoad];

    PFUser *currenUser = [PFUser currentUser];
    if (!currenUser) {
        self.loginViewController = [[BRLoginViewController alloc] init];
        [self presentViewController:self.loginViewController animated:NO completion:nil];
    }
}

One of my first questions is that I have to set animated to NO so this works correctly (there was an error that says Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0xaa43f70>.)

Okay, when Login viewController shows and I login with my username and password I have the next method when I touch the loginbutton:

- (IBAction)logInButton:(id)sender
{
        [PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError *error) {
            if (error) {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:[error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alertView show];
            } else {
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
        }]; 
}

The problem is when the app performs the next line [self.navigationController popToRootViewControllerAnimated:YES]; because it stays in LoginViewController and don't perform the transition to my rootView (InboxViewController). But If I stop the app and then run it again it's correctly login and the InboxViewController shows instead of LoginViewController as it should be.

Sorry for the long post but I really don't know why this isn't working :_(.