我正在使用 Parse.com 作为我的 iOS 应用程序的后端。
我有一个名为“用户”的类。在这堂课中,我有一张名为“图片”的用户头像。
目前我有点坚持如何为我的 currentUser 获取这张图片并将其显示在我的故事板视图控制器中的 UIView(而不是 UIImage)中。
也许你们有一些示例代码?
提前致谢!
我正在使用 Parse.com 作为我的 iOS 应用程序的后端。
我有一个名为“用户”的类。在这堂课中,我有一张名为“图片”的用户头像。
目前我有点坚持如何为我的 currentUser 获取这张图片并将其显示在我的故事板视图控制器中的 UIView(而不是 UIImage)中。
也许你们有一些示例代码?
提前致谢!
阿米特,抱歉你的代码对我不起作用,我的应用程序崩溃了。
这是我的解决方案:
PFUser *cUser = [PFUser currentUser];
PFFile *pictureFile = [cUser objectForKey:@"picture"];
[pictureFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error){
[_currentUserImage setImage:[UIImage imageWithData:data]];
}
else {
NSLog(@"no data!");
[_currentUserImage setImage:[UIImage imageNamed:@"profile"]]; //Set Custom Image if there is no user picture.
}
}];
}