简体   繁体   English

解析122错误上传

[英]Parse 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. 如果我保存文本而该字段中没有任何文本,我会在Parse.com中收到以下错误消息:更新失败-操作无法完成(解析错误122。)如果我按OK,然后尝试使用“取消”取消视图(按钮项)应用程序崩溃。 I think a valid file name at Parse.com has to contain at least 1 character. 我认为Parse.com上的有效文件名必须包含至少1个字符。 Maybe I can do do something to stop the user from saving when not enter text? 也许我可以做一些事情来阻止用户在不输入文本的情况下进行保存? Any ideas? 有任何想法吗?

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];
}

1 1

Test if your one letter theory is true. 测试您的一个字母理论是否正确。 Change: 更改:

NSString *filename = [NSString stringWithFormat:@"%@", nameTextField.text];

To: 至:

NSString *filename = [NSString stringWithFormat:@"file%@", nameTextField.text];

2 2

Or just avoid it if it's blank. 或者,如果它为空白,请避免使用它。 So this: 所以这:

NSString *filename = [NSString stringWithFormat:@"%@", nameTextField.text];

PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[profile setObject:imageFile forKey:@"profileimageFile"];

Becomes: 变为:

if (nameTextField.text) {
    NSString *filename = [NSString stringWithFormat:@"%@", nameTextField.text];

    PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
    [profile setObject:imageFile forKey:@"profileimageFile"];
}

3 3

Also, what is this: 另外,这是什么:

if(nameTextField.text.length==0 && titleTextField.text.length==0 && locationTextField.text.length==0)

It's doesn't appear to be connected to anything? 它似乎没有连接到任何东西吗?

4 4

You call this twice in quick succession, and then again right after the file saves. 您快速连续调用两次,然后在文件保存之后再次调用。 Is there something in the method that makes the repetitive calls necessary? 方法中是否有某些东西需要重复调​​用?

[hud hide:YES];

5

Your if statement doesn't appear to be connected to anything: 您的if语句似乎未与任何内容关联:

if(nameTextField.text.length==0 && titleTextField.text.length==0 && locationTextField.text.length==0)

I'm assuming you want: 我假设您想要:

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];
        }
    }];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM