我已经在Parse.com的User类中上传了另一个数组列,我希望将该数组返回并在表视图中显示它。该数组是用户键入的阻止用户列表。
NSString *usernameBlock = [self.blockUser.text];
PFUser *blockedUser = [PFUser currentUser];
[blockedUser addObject:usernameBlock forKey:@"blockedUsers"];
self.blockedRelation = [blockedUser relationForKey:@"blocked"];
[blockedUser saveInBackground];
这会添加另一个用户名数组列。
现在在我的blockedUserVC中,我想查询该列并让数组显示在tableView中。
我试过以下但我一直在崩溃: -
//tried this
PFQuery *query = [PFQuery queryWithClassName:@"_User"];
[query whereKey:@"blockedUsers" equalTo:[PFUser currentUser]];
[query valueForKey:@"blockedUsers"];
[query whereKey:@"blockedUsers" containedIn:_blockedUser]; //blocked user is an array
[query orderByAscending:@"username"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if (error) {
// NSLog(@"error %@ %@", error, [error userInfo]);
} else {
self.blockedUser = objects; //blockedUser is an array
[self.tableView reloadData];
}
}];
我应该如何查询,以便获得该数组?
crashlog:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<PFQuery 0x7fc13150fbe0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key blockedUsers.'
答案 0 :(得分:1)
[query valueForKey:@"blockedUsers"];
此行导致崩溃,请改用use include。 https://parse.com/docs/ios/guide
另外,我认为:
[query whereKey:@"blockedUsers" containedIn:_blockedUser]; //blocked user is an array
应该是:
[query whereKey:@"blockedUsers" containsAllObjectsInArray:@[_blockedUser]]; //blocked user is an array
这不会导致崩溃,但它会屈服于(据我所知)错误的结果。