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

Navigation Controller between view controller and table view controller

Any ideas on how to add a Navigation Controller in iOS7 between a Table View and View Controller. As soon as I embed the Navigation Controller to the table view the app crashes. With out the navigation controller it works fine. But then the Table View becomes a View Controller. This is the code I'm using:

[self.navigationController performSegueWithIdentifier:@"setup" sender:self];

10 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

If you have it - What does your prepareForSegue method look like?

Here is my storyboard:

alt text http://sv.tinypic.com/r/1ztdnb/8

This is the code:

            <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 performSegueWithIdentifier:@"setup" sender:self];


            }
        }];
    }
}

</p>
            ``` 
Thomas Nilsen
Thomas Nilsen
14,957 Points

remove that:

else {
             [self.navigationController performSegueWithIdentifier:@"setup" sender:self];


            }

But how do I get to the next controller then?

Thomas Nilsen
Thomas Nilsen
14,957 Points

If your segue is connected from the "Sign Up" button, and it's a push-segue you don't need it. I should have explained a bit instead of just showing code.

Take a look at this example: https://www.dropbox.com/sh/otilgs627pksjke/p2II6Sk2Dh

Thanks man. Do you have the whole project so I can try it out?

Thomas Nilsen
Thomas Nilsen
14,957 Points

What do you mean? That was just something I made to make it easier to understand :)

Yes. But you cant open the project with only one file. Everything is missing

Thomas Nilsen
Thomas Nilsen
14,957 Points

That's strange. I can mail it to you. What's your email?

Thanks it worked out anyway