0

currentUser に添付されたイメージの取得に問題があります。解析する情報を保存するために使用しているコードは次のとおりです。

-(IBAction)saveButtonAction:(id)sender {

PFUser *currentUserSave = [PFUser currentUser];

userBioString = userBio.text;
genderFieldString = genderField.text;
ageFieldString = ageField.text;

profilePictureData = UIImageJPEGRepresentation(profilePicture.image, .05f);
PFFile *userProfilePictureFileContainer = [PFFile fileWithData:profilePictureData];

currentUserSave[@"userBioParse"] = userBioString;
currentUserSave[@"userGenderParse"] = genderFieldString;
currentUserSave[@"ageFieldParse"] = ageFieldString;
[currentUserSave setObject:userProfilePictureFileContainer forKey:@"userPictureParse"];
userImageData = UIImageJPEGRepresentation(profilePicture.image, 0.5);
userProfileImageFile = [PFFile fileWithData:userImageData];
[currentUserSave setObject:userProfileImageFile forKey:@"userPictureParse"];



[[PFUser currentUser] saveInBackground];

基本的に、ユーザープロファイルをロードするために情報を呼び戻そうとしています。私がこれまでに持っているものは次のとおりです(それほど多くはありません)。

PFQuery *queryUser = [PFUser query];
[queryUser whereKey:@"username" equalTo:[[PFUser currentUser]username]];
[queryUser getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error){


    PFFile *theImage = [object objectForKey:[PFUser currentUser][@"userPictrueParse"]];
    NSData *imageData = [theImage getData];
    UIImage *profileImage = [UIImage imageWithData:imageData];

    if (profileImage == nil) {
        profilePicture.image = [UIImage imageNamed:@"765-default-avatar.png"];
    } else {
        profilePicture.image = profileImage;
    }

}];
4

3 に答える 3

2

ImageView の代わりに ParseImageView を使用し、次のコードで画像を設定できます-

try{
    ParseFile image = ParseUser.getCurrentUser().getParseFile("picture");
    if (image != null) {

        parseImgView.setParseFile(image);
        parseImgView.loadInBackground();
    }
}catch(Exception e)
{
    e.printStackTrace();
}
于 2015-06-12T07:49:50.923 に答える
0

同じ問題を抱えている人にとって、問題を解決するために私がしなければならなかったのは、profilePicture クラスを UIImageView から PFImageView に切り替えることだけでした。それが完了すると、このコードを使用して解析からファイルを呼び出すことができました。

PFUser *currentuser = [PFUser currentUser];
PFFile *pictureFile = [currentuser objectForKey:@"userPictureParse"];
profilePicture.file = pictureFile;
[profilePicture loadInBackground];

超超シンプル。助けてくれてありがとう。

于 2015-06-13T04:44:16.643 に答える