我使用Parse作为我的应用程序的后端,似乎配置文件照片显示不正确,如图所示:
john_appleseed的照片上有一条黑条。
这是我保存个人资料图片的代码:
NSData *profileData = UIImagePNGRepresentation(cell1.profileView.image);
PFFile *profileFile = [PFFile fileWithName:@"profilePhoto" data:profileData];
[profileFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (!error)
{
if (succeeded)
{
[user setObject:profileFile forKey:@"profilePhoto"];
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (!error)
{
}
else
{
}
}];
}
}
}];
这是我如何检索图像:(在PFQueryTableViewController内)
- (PFQuery *)queryForTable
{
//NSLog(@"called");
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString *filter = [defaults objectForKey:@"topicFilter"];
NSLog(@"queryfortable: %@", filter);
PFQuery *query = [PFQuery queryWithClassName:@"Questions"];
[query includeKey:@"user"];
[query whereKey:@"category" equalTo:filter];
[query orderByDescending:@"createdAt"];
return query;
}
- (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == self.objects.count)
{
return nil;//this is for the load more cell.
}
return [self.objects objectAtIndex:indexPath.section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
中的
PFUser *user = [object objectForKey:@"user"];
PFImageView *profileImgView = (PFImageView *)[cell viewWithTag:1];
profileImgView.layer.cornerRadius = profileImgView.frame.size.height/2;
profileImgView.layer.masksToBounds = YES;
PFFile *file = user[@"profilePhoto"];
profileImgView.file = file;
[profileImgView loadInBackground];
任何想法?非常感谢。
答案 0 :(得分:1)
您应该在主线程上更新用户界面。由于您在后台加载某些东西,您应该通知主线程它需要更新一个对象。 NSString *requestURL = file.url; // Save copy of url locally (will not change in block)
[file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
//dispatch on main thread
UIImage *image = [UIImage imageWithData:data];
} else {
NSLog(@"Error on fetching file");
}
}];
正在异步下载文件。
以下是一个示例,您可以根据自己的需要进行更改,只是为了说明,更新回调中的UI组件会带来好处;这是基于Parses自己的BFS:
with=FALSE