0

我正在使用 Parse.com 从数据库中检索我需要的数据。

在我的表格视图中,我有一个根据此查询更改颜色的图像,该查询使用显示的帖子调用 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];
}
4

1 回答 1

0

这些图像只有一种颜色,因为您的测试:

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

仅检查当前用户是否有赞成票。它不会检查他当前用户是否与“当前”赞成票有关系(这将在您的数组中用于填充表格视图)。

您需要更改逻辑以检查关系。

于 2013-11-23T20:06:25.170 回答