解析以下 PFUser
Parse following PFUser
我正在尝试在我的 ios9 项目上使用 parse 执行 follow 操作,但我遇到了一个小问题当使用 objectId 从解析中检索 PFUser 时,任何人都可以帮助我(问题在于将当前用户的用户 ID 添加到所关注的用户)
- (IBAction)followButtonAction:(id)sender {
PFQuery * query = [PFUser query];
[query whereKey:@"objectId" equalTo:_a.userId];
NSArray *objects = [query findObjects];
PFUser *user= objects.firstObject;
//add the user ID for the cell we are following to the array of followed items in the user class in parse
[[PFUser currentUser] addUniqueObject:_a.userId forKey:@"followed"];
[[PFUser currentUser] saveInBackground];
//add the user ID to the user that the user followed
[user addUniqueObject:[PFUser currentUser].objectId forKey:@"followers"];
[user saveInBackground];
}
假设您的问题是关于 long-运行 操作(根据您的评论):
您的查询正在主线程上执行,因为您调用了 [query findObjects]
。请改用 findObjectsInBackgroundWithBlock
,并将其后的所有代码放在回调中。
我正在尝试在我的 ios9 项目上使用 parse 执行 follow 操作,但我遇到了一个小问题当使用 objectId 从解析中检索 PFUser 时,任何人都可以帮助我(问题在于将当前用户的用户 ID 添加到所关注的用户)
- (IBAction)followButtonAction:(id)sender {
PFQuery * query = [PFUser query];
[query whereKey:@"objectId" equalTo:_a.userId];
NSArray *objects = [query findObjects];
PFUser *user= objects.firstObject;
//add the user ID for the cell we are following to the array of followed items in the user class in parse
[[PFUser currentUser] addUniqueObject:_a.userId forKey:@"followed"];
[[PFUser currentUser] saveInBackground];
//add the user ID to the user that the user followed
[user addUniqueObject:[PFUser currentUser].objectId forKey:@"followers"];
[user saveInBackground];
}
假设您的问题是关于 long-运行 操作(根据您的评论):
您的查询正在主线程上执行,因为您调用了 [query findObjects]
。请改用 findObjectsInBackgroundWithBlock
,并将其后的所有代码放在回调中。