我正在查询我的解析数据库以从特定表中下载图像。 一切正常,除非我认为是一个小故障。
仅在我稍微滚动UITableView
时才会显示图像。
是的我正在异步下载图像。
干杯
更新
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;
}
答案 0 :(得分:0)
如果图像占用大量内存,则会将其删除以释放内存。
然后,当您的表视图尝试绘制它们时,它必须再次下载它们,这需要时间。
解决方案是将图像下载到手机上的磁盘,然后从磁盘上的文件中加载图像。