0

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];
}
kAiN
  • 2,559
  • 1
  • 26
  • 54
  • You always see all blue or grey? Where is that second block of code? Where are you using `UpVoteCurrentUser`? – Wain Nov 23 '13 at 19:57
  • The image is always gray and upvote ... is the array that contains the results of the query that I specified in my application – kAiN Nov 23 '13 at 20:02
  • I edited my question to show you where using the array – kAiN Nov 23 '13 at 20:03

1 Answers1

0

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.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Yes, but I can not understand how ... I realized that there was a mistake :) – kAiN Nov 23 '13 at 20:07
  • It's hard to follow your data model with the information you have given. You need to get the relation for each row of the table - do you have that currently? – Wain Nov 23 '13 at 20:10
  • Relations don't make it very easy to test containment, you can just get a query to run to test, but that isn't too efficient. It will likely be easier to get all of the (recently) liked posts and compare object ids... – Wain Nov 23 '13 at 20:12
  • Currently through the two "Void" that I posted in the question I get a report with the CurrentUser when the button is selected – kAiN Nov 23 '13 at 20:12
  • Take a look at http://stackoverflow.com/questions/17331572/parse-how-do-i-query-using-pfrelation-when-i-just-have-pfuser and see if it helps – Wain Nov 23 '13 at 20:18
  • They try to do anything I also suggested by Wain with the link using the query that calls the report equivalent to PFUser Current user but still can not seem to make it clear to Tableview which posts have a relationship with the CurrentUser and which ones do not have the report .. . No idea about this? – kAiN Nov 25 '13 at 13:25