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 trialYOL O!
57 PointsParse 122 error upload
If I save text without having any text in the field I get this error message in Parse.com: Update Failure - The operation couldn't be completed(Parse error 122.) If I press OK and then try to dismiss the view with Cancel(a button item) the app crashes. Any ideas? I think a valid file name at Parse.com has to contain at least 1 character. But how do I do something to stop the user from saving then?
This my code:
- (IBAction)save:(id)sender {
// Create PFObject with profile information
PFUser *profile = [PFUser currentUser];
[profile setObject:nameTextField.text forKey:@"name"];
[profile setObject:titleTextField.text forKey:@"title"];
[profile setObject:locationTextField.text forKey:@"location"];
// Profile image
NSData *imageData = UIImageJPEGRepresentation(profileImageView.image, 0.8);
NSString *filename = [NSString stringWithFormat:@"%@", nameTextField.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[profile setObject:imageFile forKey:@"profileimageFile"];
// Show progress
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = @"Updating";
[hud show:YES];
// Upload profile to Parse
if(nameTextField.text.length==0 && titleTextField.text.length==0 && locationTextField.text.length==0)
[hud hide:YES];
[profile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
[[[UIAlertView alloc] initWithTitle:@"Profile Information" message:@"Fill in atleast one field" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[hud hide:YES];
}
else {
// Show success message
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Successfully updated profile" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[hud hide:YES];
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:@"profile" sender:self];
}
}];
}
- (IBAction)Cancel:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:@"profile" sender:self];
}
3 Answers
YOL O!
57 PointsBen Jakuben the saver! Please!!
YOL O!
57 PointsAnyone?
Ben Jakuben
Treehouse TeacherSorry for the delay...what is filename
being set to when you get this error?