【问题标题】:fetching 1 image from parse.com从 parse.com 获取 1 张图片
【发布时间】:2015-06-10 12:40:03
【问题描述】:

我在这里看到很多帖子,社区给出了惊人的答案。不幸的是,没有人能够帮助或指导我解决我需要帮助的问题。我试图“获取”“当前用户”上传的图像以在同一个“UIImageView”上解析

以下是我如何上传照片的示例

我的帐户.h

  @property (strong, nonatomic) IBOutlet UIImageView *imageView;

- (IBAction)UploadPhoto:(id)sender;
- (IBAction)selectPhoto:(id)sender;

我的帐户.m

- (IBAction)UploadPhoto:(UIButton *)sender {

PFObject *User = [PFUser currentUser];
NSData *imageData = UIImageJPEGRepresentation(_imageView.image, 0.8);
NSString *filename = [NSString stringWithFormat:@"%@.png", _username.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[User setObject:imageFile forKey:@"ProfilePicture"];

// Show progress
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = @"Uploading";
[hud show:YES];

// Upload Profile Picture to Parse
[User saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    [hud hide:YES];
    if (!error) {
        // Show success message
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Complete" message:@"Successfully uploaded profile picture" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

        // Dismiss the controller
        //[self dismissViewControllerAnimated:YES completion:nil];

    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Failure" message:[error localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

    }


}];

}

老实说,我不知道从这里去哪里!照片完美地上传到 parse.com 上的类...但我无法让它在每次应用程序 viewdidloads 这个控制器时显示。

我试过了

- (void)viewDidLoad {

[super viewDidLoad];

PFFile * myPFFile = [[PFUser currentUser] objectForKey:@"ProfilePicture"];
[myPFFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    if (!error) {
        UIImage *image = [UIImage imageWithData:data];
        // image can now be set on a UIImageView
    }
}];

但我在 UIImage *image = [UIImage imageWithData:data]; 上得到“图像”的未使用变量;

我做错了什么。有人请帮我解决我丢失的任何代码。我已经做了 3 个月了,它阻止了我前进.... PPPPLLZZZ 帮助

【问题讨论】:

  • 您需要将图像分配给 uiimageview,如 imageView.image = image。

标签: ios parse-platform pffile pfimageview


【解决方案1】:

我错过了什么?您是否将图像放在 imageView 中? (这就是为什么你会得到'未使用的“图像”变量')

在你的情况下:

[imageView setImage:image];

【讨论】:

  • 是的,是的,是的,是的,是的,是的,是的,是的,是的,是的,是的,是的,是的,是的,是的,是的,是的,非常感谢@Mute Dan!
  • 是的....如果我想改变 [PFUser currentUser] 用一个类替换它我该怎么做?
猜你喜欢
  • 1970-01-01
  • 2016-07-27
  • 2013-07-27
  • 2023-03-13
  • 1970-01-01
  • 2022-01-01
  • 2013-02-14
  • 2012-02-10
  • 1970-01-01
相关资源
最近更新 更多