我正在使用Parse.com从数据库中检索我需要的数据。
在我的tableview中,我有一个根据此查询更改颜色的图像,该图像使用显示的帖子调用CurrentUser的报告。
-(void)QueryForUpVote {
PFQuery *QueryForUpVotePost = [PFQuery queryWithClassName:FF_POST_CLASS];
[QueryForUpVotePost whereKey:@"UP_Vote" equalTo:[PFUser currentUser]];
[QueryForUpVotePost findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
UpVoteCurrentUser = [[NSMutableArray alloc] init];
for (PFObject *ObjectForUpVote in objects) {
[UpVoteCurrentUser addObject:ObjectForUpVote];
}
[self.FFTableView reloadData];
}
}];
}
在Tableview中我添加了这个以确保如果有一个帖子与CurrentUser有关系(就像一种社交网络)
if ([[PFUser currentUser] objectForKey:@"UP_Vote"] ) {
CellaIMG.MedalCount.image = [UIImage imageNamed:@"FFIMG_Medal_Blu"];
CellaIMG.AddGoPoint.tag = indexPath.row;
[CellaIMG.AddGoPoint addTarget:self action:@selector(AddGoPointAction:) forControlEvents:UIControlEventTouchUpInside];
} else {
CellaIMG.MedalCount.image = [UIImage imageNamed:@"FFIMG_Medal"];
CellaIMG.AddGoPoint.tag = indexPath.row;
[CellaIMG.AddGoPoint addTarget:self action:@selector(DecrementGoPoint:) forControlEvents:UIControlEventTouchUpInside];
}
我目前的问题是,TableView无法识别将CurrentUser与帖子一起显示的关系...当用户与帖子有特定关系时,我提供的图像应该变为灰色到蓝色...我在哪里做错了?
MutableArray用于:
- (void)AddGoPointAction:(id)sender {
PFObject *AddGoPointToPost = [self.UpVoteCurrentUser objectAtIndex:[sender tag]];
[AddGoPointToPost incrementKey:FF_POST_GOPOINTPOST byAmount:[NSNumber numberWithInt:1]];
PFRelation *RelationForVote = [AddGoPointToPost relationforKey:@"UP_Vote"];
[RelationForVote addObject:[PFUser currentUser]];
[AddGoPointToPost saveInBackground];
[self.FFTableView reloadData];
}
- (void)DecrementGoPoint:(id)sender {
PFObject *AddGoPointToPost = [self.UpVoteCurrentUser objectAtIndex:[sender tag]];
[AddGoPointToPost incrementKey:FF_POST_GOPOINTPOST byAmount:[NSNumber numberWithInt:-1]];
PFRelation *RelationForVote = [AddGoPointToPost relationforKey:@"UP_Vote"];
[RelationForVote removeObject:[PFUser currentUser]];
[AddGoPointToPost saveInBackground];
[self.FFTableView reloadData];
}
答案 0 :(得分:0)
图片只有一种颜色,因为您的测试:
if ([[PFUser currentUser] objectForKey:@"UP_Vote"] ) {
仅检查当前用户是否有upvote。它无需检查当前用户是否与“当前”upvote(将在您的数组中用于填充表视图)有关系。
您需要更改逻辑以检查关系。