iOS解析个人资料图片上的黑条(PFImageView)

标签 ios objective-c parse-platform pfimageview

我正在使用 Parse 作为我的应用程序的后端,个人资料照片似乎没有正确显示,如图所示: notice the john appleseed

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];

有什么想法吗?非常感谢。

最佳答案

您应该在主线程上更新用户界面。因为你在后台加载一些东西,你应该通知主线程它需要更新一个对象。 loadInBackground 正在异步下载文件。

这是一个示例,您可以根据需要进行更改,只是为了说明,在回调中更新 UI 组件有它的好处;这是基于 Parses 自己的 AnyPic :

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");
    }
}]; 

关于iOS解析个人资料图片上的黑条(PFImageView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32300666/

相关文章:

ios - 如何在 Swift 中跳过 for 循环中的索引

iOS 开发 : Is it necessary to change the class of the View Controller in the storyboard?

ios - 取消对 View 的多次触摸

ios - 升级parse cocoapod后PFFacebookUtils未解析

swift - 如何制作原型(prototype)单元格 'disappear' 当它是 'empty'(不可点击)

ios - CABasicAnimation 起源于右上角而不是中心

iphone - 如何通过 HTTP post 将数据字节发送到 .NET 服务器

javascript - get() 解析查询结果是否执行另一个数据库调用?

ios - SFSafariViewController OAuth 实现

ios - 使用 UICollectionView 和 UICollectionViewCells 进行类似 twitter 的提要设计