我不确定它是否是我的代码,或者它是否解析没有正确获取查询。我有一张" Photo"类表填充了作为照片的PFFiles,每张照片都有相应的字符串类型标题。当我查询表/类时,字幕按正确的降序获取,但很少拍照。因此,照片没有正确的相应字幕(字符串)。我为PFFile使用了getDataInBackgroundWithBlock方法,因为我得到了臭名昭着的#34;有一个长时间运行的解析操作"没有警告。救命!这是我的代码:
- (void)queryParse
{
PFQuery *query = [PFQuery queryWithClassName:@"Photo"];
[query orderByDescending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *object in objects) {
[objectIDArray addObject:object.objectId];
NSString *postedBy = object[@"postedBy"];
[postedByFeedArray addObject:postedBy];
NSString *caption = object[@"caption"];
[captionFeedArray addObject:caption];
PFFile *file = object[@"photoFile"];
[file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
[photoFeedArray addObject:data];
}
dispatch_async(dispatch_get_main_queue(), ^{
[_activityIndicator stopAnimating];
[_tableView reloadData];
});
}];
}
} else {
NSLog(@"ERROR: %@", error);
}
}];
}
答案 0 :(得分:0)
展开PFFiles。
func loadData() {
var findUser = PFUser.query()
findUser.whereKey("username", equalTo: profileUser.username)
findUser.getFirstObjectInBackgroundWithBlock { (object:PFObject!, error: NSError!) -> Void in
if (error == nil) {
if let profileImage:PFFile = object["profileImage"] as? PFFile {
profileImage.getDataInBackgroundWithBlock({ (imageData:NSData!, error: NSError!) -> Void in
if (error == nil) {
let image:UIImage = UIImage(data: imageData)!
self.profileImageView.image = image
}
else{
println(error)
self.presentErrorMessage(error)
}
})
}
}
else {
// Log details of the failure
println(error)
self.presentErrorMessage(error)
}
}
}