【发布时间】: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