iosuitableviewparse-platformpfrelation

PFRelation with post of CurrentUser in TableView


I'm using Parse.com to retrieve the data I need from the database.

In my tableview I have an image that changes color according to this query that invokes the report of the CurrentUser with the posts that are displayed.

-(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];
        }
    }];
}

In Tableview I added this to make sure that if there was a post that has a relationship with the CurrentUser (Like a kind of social networks)

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];

        }

My current problem is that the TableView does not recognize the relationships that have the CurrentUser displayed with the post ... The image that I have provided should become gray to blue when the user has a specific relationship with the post ... Where am I doing wrong?

The MutableArray is used in:

- (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];
}

Solution

  • The images are only one colour because your test:

    if ([[PFUser currentUser] objectForKey:@"UP_Vote"] ) {
    

    Is only checking if the current user has an upvote. It does nothing to check if he current user has a relation to the 'current' upvote (that would be in your array being used to populate the table view).

    You need to change the logic to check the relationship.