1

アプリのバックエンドとして 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];

何か案は?どうもありがとう。

4

1 に答える 1

1

メイン スレッドでユーザー インターフェイスを更新する必要があります。バックグラウンドで何かをロードしているため、オブジェクトを更新する必要があることをメインスレッドに通知する必要があります。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");
    }
}]; 
于 2015-08-30T20:59:13.150 に答える