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
Christian Bryant
Front End Web Development Techdegree Student 8,296 PointsTrouble with If / Else Condtion
Im currently working on the build a self-destructing message app and am stuck on a if/else issue in my code. The first part where we are checking to make sure there is a value in the text box. When I run the app, and fill out the tex box's the code keeps hitting the alertView stating that I need to enter a username, password, and address. I don't see any issue with the code though is the problem.
My code is below:
- (IBAction)signup:(id)sender {
NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *password = [self.passwordField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *email = [self.emailFeld.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([username length] == 0 || [password length] == 0 || [email 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];
[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];
}
}];
}
}
Any suggestions?
Thanks!
5 Answers
obey me
1,135 Pointsif you want you could just say if there is nothing in username.text or password.text
if([_usernamefield.text isEqualToString:@""]||[_passwordfield.text isEqualToString:@""])
{
// do whatever you want
}
else{
// do whatever you want
}
Christian Bryant
Front End Web Development Techdegree Student 8,296 PointsThat kind of worked... but now i get this error in the log:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't remove the username field for a PFUser.'
obey me
1,135 Pointsi think its because you didn't set it up like
PFUser *newUser = [PFUser user];
newUser.username = username.text;
newUser.password = password.text;
newUser.email = emai.textl;
Christian Bryant
Front End Web Development Techdegree Student 8,296 Pointshmm.. I switched it too that and still the same. Not too sure what the error really means
obey me
1,135 Pointsif you want you could put your project online and i could take a look at it for you
Christian Bryant
Front End Web Development Techdegree Student 8,296 Pointsokay, I need to get GitHub on this laptop, and Ill post a link to the repository here shortly.
Christian Bryant
Front End Web Development Techdegree Student 8,296 PointsHere is the link > https://github.com/ChristianRVA/Ribbit
Christian Bryant
Front End Web Development Techdegree Student 8,296 Pointswhoops! looks like some of the files aren't there.. hang on .. need to do another commit