0
我正在查詢我的分析數據庫以從特定表中下載圖像。 一切工作,除了我認爲是一個小故障。圖像在TableViewCells中不顯示,直到向下滾動
只有當我滾動UITableView
一點時纔會出現圖像。
是的我正在異步下載圖像。
乾杯
UPDATE
PFQuery *imageQuery = [PFQuery queryWithClassName:@"WallImageObject"];
//[imageQuery orderByAscending:@"createdAt"];
[imageQuery whereKey:@"geoPoint" nearGeoPoint:currentLocationInGeoPoint withinKilometers:3.0];
NSLog(@"PFGeoPoint current location: %f and %f", currentLocationInGeoPoint.latitude, currentLocationInGeoPoint.longitude);
[imageQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if (error)
{
NSLog(@"Error retreiving images: %@", error.localizedDescription);
}else
{
for (PFObject *wallImageObject in objects) {
WallImage *wallImage = [[WallImage alloc] init];
wallImage.fbID = wallImageObject[@"UserId"];
wallImage.username = wallImageObject[@"userName"];
wallImage.createdAt = wallImageObject.createdAt;
[[NSOperationQueue pffileOperationQueue]addOperationWithBlock:^{
wallImage.image = [UIImage imageWithData:[(PFFile *)wallImageObject[@"image"] getData]];
[[NSNotificationCenter defaultCenter]postNotificationName:N_ImageDownloaded object:nil];
}];
wallImage.imageID = wallImageObject.objectId;
wallImage.geoPoint = wallImageObject[@"geoPoint"];
NSLog(@"Image latitude: %f and londitude %f", wallImage.geoPoint.latitude, wallImage.geoPoint.longitude);
[[DataStore instance].wallImages addObject:wallImage];
}
NSLog(@"%lu images in this location", (unsigned long)[[DataStore instance].wallImages count]);
if ([delegate respondsToSelector:@selector(communicationDidGetWallImages:)]) {
[delegate communicationDidGetWallImages:YES];
}
}
這裏,我顯示圖像
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Post";
FeedPhotoCell *feedPhotoCell = (FeedPhotoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
WallImage *wallImage = [DataStore instance].wallImages[indexPath.row];
[feedPhotoCell.photoPost setImage:wallImage.image];
NSString *facebbokUserID = wallImage.fbID;
NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large",facebbokUserID];
NSURL *facebookProfilePicURL = [NSURL URLWithString:urlString];
[feedPhotoCell.profilePhoto setImageWithURL:facebookProfilePicURL];
feedPhotoCell.profilePhoto.layer.cornerRadius = 10.0;
feedPhotoCell.profilePhoto.layer.borderColor = [UIColor orangeColor].CGColor;
feedPhotoCell.profilePhoto.layer.borderWidth = 1.0;
feedPhotoCell.profilePhoto.clipsToBounds = YES;
NSLog(@"image cell height: %f", feedPhotoCell.photoPost.image.size.height);
return feedPhotoCell;
}
如果可能,這將有助於提供用於下載和顯示圖像的代碼。 – Brian
這聽起來像你在後臺線程上設置圖像。您可能必須將'imageView.image = ...'分派到主線程,以在表視圖重繪之前使更改生效。 – Eagerod
我按照你的說法修復了它。我開始下載cellForRowAtIndex中的圖像,當它發出響應時,我將圖像加載到主線程中。謝謝 – Camus