2013-11-23 24 views
0

我正在使用Parse.com從數據庫中檢索我需要的數據。PFRelation with CurrentUser在TableView中的帖子

在我的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]; 
     } 
    }]; 
} 

在泰伯維我加入這個以確保如果有具有與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

你總是看到所有的藍色或灰色?第二塊代碼在哪裏?你在哪裏使用'UpVoteCurrentUser'? – Wain

+0

圖像始終是灰色的並且upvote ...是包含我在我的應用程序中指定的查詢結果的數組 – kAiN

+0

我編輯了我的問題以向您展示使用數組的位置 – kAiN

回答

0

的圖像是隻有一種顏色,因爲你的測試:如果當前用戶具有給予好評

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

只是檢查。它無法檢查當前用戶是否與'當前'upvote(這將在您的數組中用於填充表視圖)有關係。

您需要更改邏輯以檢查關係。

+0

是的,但我無法理解how .. 。我意識到有一個錯誤:) – kAiN

+0

很難用你提供的信息來跟蹤你的數據模型。你需要獲得表格每一行的關係 - 你現在有嗎? – Wain

+0

關係不會使測試遏制變得非常容易,您可以獲得一個查詢來運行測試,但這不是太高效。它可能會更容易得到所有(最近)喜歡的帖子和比較對象ID ... – Wain