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 Signing Up New Users: Part 2 (PFUser)

Instead of going back to the Inbox, when I sign up in simulator it goes back to the sign in view. Why is this please?

I believe I followed Ben's instructions step-by-step.

Stone Preston
Stone Preston
42,016 Points

can you post your code

Sure, for SigninViewController.m:

#import "SigninViewController.h"
#import <Parse/Parse.h>

@interface SigninViewController ()

@end

@implementation SigninViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (IBAction)signup:(id)sender {
    NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSString *password = [self.passwordField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSString *email = [self.emailField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    if ([username length] == 0  || [password length] == 00 || [email length] == 00) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!"
                                                            message:@"Make sure you enter a username, password, and email address!"
                                                           delegate:nil cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil];
        [alertView show];
    } else {
        PFUser *newUser = [PFUser user];
        newUser.username = username;
        newUser.password = password;
        newUser.email = email;

        [newUser signUpInBackgroundWithBlock:^(BOOL succeeded, 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];
            }
        }];
    }

}
@end'''

For InboxViewController.m:
'''#import "InboxTableViewController.h"
#import <Parse/Parse.h>

@interface InboxTableViewController ()

@end

@implementation InboxTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    [self performSegueWithIdentifier:@"showLogin" sender:self];
}


@end

Any more code I need to include?

2 Answers

Stone Preston
Stone Preston
42,016 Points

alright I think the issue lies with your storyboard setup. your inbox is embedded in a navigation controller. the showLogin segue is connected to another navigation controller. the root of that other navigation controller is the log in view, which explains why you see the log in view whenever you call popToRootViewController.

you need to remove that additional navigation controller so that your showLogin segue goes directly from the inbox to the login view (not from the inbox to another navigation controller)

you will have to delete the navigation controller that has the log in view embedded in it, and then recreate the showLogin segue

this way, the inbox, log in, and signup views will have be children of the same navigation controller, and the inbox will be the root, thus calling popToRootViewController from sign up will pop you back to the inbox as intended

Thank you for helping me out Stone - I appreciate it!

Stone Preston
Stone Preston
42,016 Points

no problem glad I could help

Stone Preston
Stone Preston
42,016 Points

try adding an if statement in the inbox viewDidLoad that only performs the segue if the user is signed in:

@implementation InboxTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //if there is a current signed in user
    if ([PFUser currentUser]) {
    [self performSegueWithIdentifier:@"showLogin" sender:self];
    }
}

besides the above code, I dont really see anything wrong with your code. if the code above does not fix it can you post a screen shot of your storyboard also, I see you named your sign up controller sign in view controller. that might be confusing since signing in is the same thing as logging in.

Thanks for that - I tried adding the if statement but no change, unfortunately. Yes, good point with sign in / sign up - I've amended it. Here's the screenshot of my storyboard:

http://postimg.org/image/hr3i1i3xb/