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

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 :_(.