我想在我的uitable视图中获取用户个人资料图片列表,我该怎么做,这是我到目前为止
PFQuery *query = [PFQuery queryWithClassName:@"UserPhoto"];
PFUser *user = (PFUser *)[self.users objectAtIndex:[indexPath row]];
[query whereKey:@"user" equalTo:user];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error){
PFFile *theImage = [object objectForKey:@"imageFile"];
NSData *imageData = [theImage getData];
UIImage *profileImage = [UIImage imageWithData:imageData];
NSLog(@"%@",profileImage);
if (profileImage == nil) {
} else {
cell.imageView.image = profileImage;
}
}];
下面的代码运行但输出显示为null。
我为获取当前用户的个人资料图片做了同样的事情并获得了个人资料图片,但它不会为其他用户返回图片。
请注意self.user
已包含pfusers
这里是我搜索所有用户的地方:
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
PFQuery *query = [PFUser query];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
[query whereKey:@"username" containsString:self.myTextField.text];
self.users = [query findObjects];
NSLog(@"Thing is: %@",self.users);
[self.mytableView reloadData];
}];
return YES;
}
亲切的问候
答案 0 :(得分:0)
你的第二个代码块看起来很糟糕......你发现了两次对象,但情况并非如此。试试这个:
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
PFQuery *query = [PFUser query];
[query whereKey:@"username" containsString:self.myTextField.text];
self.users = [query findObjects];
NSLog(@"Thing is: %@",self.users);
[self.mytableView reloadData];
return YES;
}