2013-11-28 51 views
0

大家好我有一個非常愚蠢的問題,但我想確保我完全理解這個東西......簡單來說有關BOOL方法的信息小小的要求

有人能'解釋他們這樣做是布爾方法 ?

- (BOOL) AssignedGoPointToPost : (PFObject *) { GoPointAssigned 
    for (PFObject * goPoint in UpVoteCurrentUser) { 
        if ([[[ goPoint objectForKey : @ " Oggetto_Votato "] objectId ] isEqualToString : GoPointAssigned.objectId ]) { 
            return YES ; 
        } 
    } 
    return NO; 
} 

,伴隨着的是我感興趣的是這個

- (void) QueryForRelationGoPointWithPost { 
    PFQuery queryForGoPointStatus * = [ PFQuery queryWithClassName : @ " goPoint "]; 
    [ queryForGoPointStatus whereKey : @ " AssegnatoDa " equalTo : [ PFUser currentUser ]] ; 
    queryForGoPointStatus.cachePolicy = kPFCachePolicyCacheThenNetwork ; 
    [ queryForGoPointStatus findObjectsInBackgroundWithBlock :^(NSArray * objects, NSError * error) { 
        if (! error) { 
            self.UpVoteCurrentUser = [ [ NSMutableArray alloc] init ] ; 
            for (PFObject * object in objects) { 
                [ self.UpVoteCurrentUser addObject : object ] ; 
            } 
            [ self.FFTableView reloadData ] ; 
        } 
    } ] ; 
} 

在這一部分,在TableView中cellforRowIndexPath的布爾查詢,我試圖通過查詢來改變形象...

if ([self AssignedGoPointToPost:ObjectPost]) { 
      CellaIMG.MedalCount.image = [UIImage imageNamed:@"FFIMG_Medal_Blu"]; 
      CellaIMG.AddGoPoint.tag = indexPath.row; 
      [CellaIMG.AddGoPoint addTarget:self action:@selector(DecrementGoPoint:) forControlEvents:UIControlEventTouchUpInside]; 

     } else { 

      CellaIMG.MedalCount.image = [UIImage imageNamed:@"FFIMG_Medal"]; 
      CellaIMG.AddGoPoint.tag = indexPath.row; 
      [CellaIMG.AddGoPoint addTarget:self action:@selector(AddGoPointAction:) forControlEvents:UIControlEventTouchUpInside]; 

     } 

讓我解釋...基本上我試圖做一個「按鈕按鈕」,當按下時將其報告保存在parse.com的databrowser中,並更改Medal Medal_Blu的圖像...

您看到的代碼調用了下面顯示的兩種操作方法。我們說這些功能很好地工作,但是當您按下按鈕「Like」時,數據和圖像的更改不會同時發生。通常甚至收到命令,並不保存甚至更新數據......我不明白我錯在哪裏。我試圖建立在教程Parse.com

https://www.parse.com/tutorials/anypic#概述

在這裏,我向您展示這兩種方法我用它來保存操作按鈕上「喜歡」

- (Void) AddGoPointAction : (id) sender { 
    FFCustomCellWithImage CellaIMG * = [ [ FFCustomCellWithImage alloc] init ] ; 
    CellaIMG.MedalCount.image = [ UIImage imageNamed : @ " FFIMG_Medal_Blu "]; 
     
    PFObject SorgenteIncrementGoPointAction * = [ self.ArrayforPost objectAtIndex : [ sender tag ]] ; 
    [ SorgenteIncrementGoPointAction incrementKey : FF_POST_GOPOINTPOST byAmount : [ NSNumber numberWithInt : +1 ]] ; 
    [ SorgenteIncrementGoPointAction saveInBackground ] ; 
     
    PFObject AssignGoPoint * = [ PFObject objectWithClassName : @ " goPoint "]; 
    [ AssignGoPoint setObject : @ " Post" Forkey : @ " type "]; 
    [ AssignGoPoint setObject : [ PFUser currentUser ] Forkey : @ " AssegnatoDa "]; 
    [ AssignGoPoint setObject : SorgenteIncrementGoPointAction Forkey : @ " Oggetto_Votato "]; 
    [ AssignGoPoint saveInBackground ] ; 
    [ self.FFTableView reloadData ] ; 
    [self QueryForRelationGoPointWithPost ] ; 
    [self QueryForPost ] ; 

     
} 

- (Void) DecrementGoPoint : (id) sender { 
    FFCustomCellWithImage CellaIMG * = [ [ FFCustomCellWithImage alloc] init ] ; 
    CellaIMG.MedalCount.image = [ UIImage imageNamed : @ " FFIMG_Medal "]; 
     
    PFObject SorgenteDecrementGoPointAction * = [ self.ArrayforPost objectAtIndex : [ sender tag ]] ; 
    [ SorgenteDecrementGoPointAction incrementKey : FF_POST_GOPOINTPOST byAmount : [ NSNumber numberWithInt : -1] ] ; 
    [ SorgenteDecrementGoPointAction saveInBackground ] ; 
     
    PFQuery DeleteGoPoint * = [ PFQuery queryWithClassName : @ " goPoint "]; 
    [ DeleteGoPoint whereKey : @ " Oggetto_Votato " equalTo : SorgenteDecrementGoPointAction ] ; 
    [ DeleteGoPoint whereKey : @ " Type " equalTo : @ " Posts "]; 
    [ DeleteGoPoint whereKey : @ " AssegnatoDa " equalTo : [ PFUser currentUser ]] ; 
    [ DeleteGoPoint findObjectsInBackgroundWithBlock :^(NSArray * RisultatoQueryDecrement , NSError * error) { 
        if (! error) { 
            for (PFObject * DeleteObject RisultatoQueryDecrement) { 
                [ DeleteObject deleteInBackground ] ; 
            } 
            [ self.FFTableView reloadData ] ; 
            [self QueryForRelationGoPointWithPost ] ; 
            [self QueryForPost ] ; 
        } 
    } ] ; 


     
     
     
    } 
用戶點擊
+0

你能分享你想要做的事嗎?你做了什麼以及你期望從我們那裏得到什麼幫助? – DivineDesert

回答

1

有人可以'簡單地解釋他們在做什麼布爾 方法?

- (BOOL) AssignedGoPointToPost : (PFObject *) { GoPointAssigned 
    for (PFObject * goPoint in UpVoteCurrentUser) { 
     if ([[[ goPoint objectForKey : @ " Oggetto_Votato "] objectId ] isEqualToString : GoPointAssigned.objectId ]) { 
      return YES ; 
     } 
    } 
    return NO; 
} 

逸岸這不是一個布爾方法,這是用返回類型BOOL(布爾值)的方法。

也有一些編譯器錯誤,首先我會嘗試刪除。

的方法應該是這樣的:

- (BOOL) AssignedGoPointToPost : (PFObject *)GoPointAssigned { 
    for (PFObject * goPoint in UpVoteCurrentUser) { 
     if ([[[ goPoint objectForKey : @ " Oggetto_Votato "] objectId ] isEqualToString : GoPointAssigned.objectId ]) { 
      return YES ; 
     } 
    } 
    return NO; 
} 

現在,

if ([[[ goPoint objectForKey : @ " Oggetto_Votato "] objectId ] isEqualToString : GoPointAssigned.objectId ]) { 
      return YES ; 

在上面的說法,高品是你是基於鍵「Oggetto_Votato」提取一些對象的字典。然後從你正在訪問的objectId應該是NSString的對象。然後從這個字符串中比較它與GoPointAssigned的objectId。

如果它們匹配,則返回YES。這是在循環內部,因此第一次匹配將返回YES並且循環將終止。如果沒有匹配,則循環過期並返回NO。