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

Ribbit SignUp

Instead of going back to inbox I would be able to move on to another viewcontroller where I can set up the profile. Any suggestions I tryied to change action to [self.navigationController popToViewController:setup animated:YES]; but i craches. Any tips?

4 Answers

Stone Preston
Stone Preston
42,016 Points

in this case you would want to perform a manual segue after your signup method finished running in the signupview controller. You will need to connect the sign up view controller to the setup view controller using a segue (control click and drag, select push segue).

Thanks as always!

I tried to drag the sign up button using a push seque with in the storyboard but then i just crashes(libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) . I guess this is because I still have the "popToRootViewControllerAnimated:YES" in the end of the code as show below. If I remove that i craches anyway:) Any idea what I'm doing wrong?

            <p>- (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] == 0 || [email length] == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Please try again."
                                                            message:@"Make sure you enter all fields."
                                                           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];

            }
        }];
    }
}


</p>
            ```
Stone Preston
Stone Preston
42,016 Points

where are you calling performSegueWithIdentifier?

Stone Preston
Stone Preston
42,016 Points

also dont create a segue from the button to the view, create a manual segue between the two view controllers. thats probably why its crashing.

Thanks man. I changed "self.navigationController popToRootViewControllerAnimated:YES" in the code abowe to "self performSegueWithIdentifier:@"ShowSetup" sender:self;" and create a manual segue between the two view controllers and naming the identifier to ShowSetup but it still crashed. Did I get it wrong anyway?

So this is the code:

            <p>#import "SignupViewController.h"
#import <Parse/Parse.h>

@interface SignupViewController ()

@end

@implementation SignupViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

}


- (void)showSetup {
    [self performSegueWithIdentifier:@"ShowSetup" sender:self];
}


- (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] == 0 || [email length] == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Please try again."
                                                            message:@"Make sure you enter all fields."
                                                           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 performSegueWithIdentifier:@"ShowSetup" sender:self];


            }
        }];
    }
}





- (IBAction)dismiss:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


@end</p>
            ```