2015-04-06 54 views
1

我在这里看过很多贴子,社区有惊人的答案。不幸的是,没有人能够帮助或指导我需要帮助。我试着去“取”的形象,“当前用户”上传到同一个“的UIImageView”从parse.com取得1张图片

下面

解析是我如何上传照片

myaccount.h的例子

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

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

myaccount.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 “图像” 未使用可变*图像= [UIImage的imageWithData:数据];

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

+0

您需要分配图像的UIImageView像imageView.image =图像。 – 2015-04-06 05:44:58

回答

0

我错过了什么?你把图像放在imageView里面吗? (这就是为什么你会得到“未使用变量‘图像’”)在您的情况

[imageView setImage:image]; 
+0

是是是是是是是是是是是是是是是是是是非常感谢@非常丹! – 2015-04-06 06:09:29

+0

谢谢@Kathiravan G – 2015-04-06 06:09:46

+0

3个月?????? – 2015-04-06 10:34:26