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

Passing data between view controllers

ok so i need to send data between two different view controllers. what i need is to pass three strings between the two so that the second view controller can submit info to parse which is not happening because when used the variables are all equal to zero.

''' IOS

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([segue.identifier isEqualToString:@"chief"]) {

    NSString *name = self.name.text;
    
    NSString *password = self.password.text;
    
    NSString *schoolEmail = self.schoolEmail.text;
    
    if ([name length] == 0 || [password length] == 0 || [schoolEmail length] == 0) {
    
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Make sure you enter a 
    

username, password, and email address!"delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

        [alertView show];

    }

    CrewChiefViewController *viewController = (CrewChiefViewController *)segue.destinationViewController;


    viewController.usernameB = name;

    viewController.passwordB = password;

    viewController.emailB = schoolEmail;




}

}

@end '''

i have tested every point possible in this and the variable always has a value. then on the next view controller when it loads there is a value but at the point of create account it is then empty

''' IOS

  • (void)viewDidLoad

{ [super viewDidLoad];

if ([self.usernameB length] == 0 || [self.passwordB length] == 0 || [self.emailB length] == 0) {

    UIAlertView *alertView2 = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"It Has not Worked"delegate:nil 

cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    [alertView2 show];

}

}

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

[self.phrase resignFirstResponder];

}

  • (IBAction)createAccount:(id)sender {

    if ([self.usernameB length] == 0 || [self.passwordB length] == 0 || [self.emailB length] == 0) {

    UIAlertView *alertView2 = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"It Has not Worked"delegate:nil 
    

cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    [alertView2 show];

    NSLog(@"error");
}



PFUser *crewChief = [PFUser user];

crewChief.username = self.usernameB;

crewChief.password = self.passwordB;

crewChief.email = self.emailB;


PFQuery *query = [PFQuery queryWithClassName:@"CrewChiefPhrase"];

[query whereKey:@"Phrase" equalTo:self.phrase.text];

[query countObjectsInBackgroundWithBlock:^(int count, NSError *error) {

    if (count > 0){

        [crewChief signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

            if (error) {

                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Sorry!" message:[error.userInfo 

objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

                [alertView show];

            }

            else{

                [self.navigationController popToRootViewControllerAnimated:YES];

            }

        }];

    } else {

        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Sorry!" message:[error.userInfo 

objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

        [alertView show];

            }

}];

}

@end '''

please help i dont know how it is possible for the value of these variables to become zero and i dont know what im doing wrong.

2 Answers

Weak memory is freed nearly instantly. It lasts until the next event loop. That's why you saw it there, but not the next instant.

I recommend learning about retain/release, it's still used even though you won't manually do it.

Unless of course, you use the C functions, since Apple never finished making ARC. You can't use audio or image functions without needing even more complex mem management than we had before arc came.

Are they strong/retain or weak props?

the text fields of name password and school email are weak. the thing i dont get though is the check on view did load never days that they are blank but when i press the button all of them are blank