简体   繁体   English

Parse.com:在TableViewCell中检索布尔值

[英]Parse.com : Retrieve Boolean Value in TableViewCell

Parse.com I'm using in my project . 我在项目中使用的Parse.com。 In my view controller I have a searchbar that fetches data from a class different from the one in which there is a Boolean value that I need. 在我的视图控制器中,我有一个搜索栏,可以从与需要布尔值的类不同的类中获取数据。

In a nutshell each cell contains a button that when pushed to disappear because is going to create a Boolean value that as I said above is in another class different from that of the main query . 简而言之,每个单元格都包含一个按钮,由于要创建一个布尔值,该按钮被按下以使其消失,正如我上面所说的,该值位于与主查询不同的另一个类中。

To help you understand: 为了帮助您理解:

The search bar fetches the data from class " _USER " where all reside registered users app 搜索栏从所有驻留的注册用户应用程序“ _USER”类中获取数据

The button instead goes into creating a boolean value in the Class " Friends " 该按钮改为在“ Friends”类中创建一个布尔值。

I can not connect the two actions ... 我无法连接两个动作...

I did some tests but I can not get the result I want .. Can you explain how I might do to fix this? 我做了一些测试,但没有得到想要的结果..您能解释一下我怎么做才能解决这个问题吗? I do not understand where is my mistake 我不明白我的错误在哪里

Here I show the query and the cellForRowAtIndexPath 在这里,我显示了查询和cellForRowAtIndexPath

- (Void) { retrieveFromParse
   
 
    PFQuery retrievePets * = [ PFQuery queryWithClassName : FF_USER_CLASS ] ;
    [ retrievePets orderByAscending : FF_USER_NOMECOGNOME ] ;
    
    [ retrievePets findObjectsInBackgroundWithBlock : ^ ( NSArray * objects , NSError * error ) {
        if ( error) {
            NSLog ( @ "% @ " , objects) ;
            allObjects = [ [ NSMutableArray alloc ] init ] ;
            for ( PFObject * object in objects) {
                [ allObjects addObject : object ] ;
                
            }
            
        }
        [ self.FFTableViewFindUser reloadData ] ;
    } ] ;
}






- ( UITableViewCell * ) tableView : ( UITableView * ) tableView cellForRowAtIndexPath : ( NSIndexPath * ) indexPath {
    static NSString * CellIdentifier = @ " CellFindUser " ;
    
    
    FFCellFindUser * cell = [ self.FFTableViewFindUser dequeueReusableCellWithIdentifier : CellIdentifier ] ;
    if ( cell) {
        cell = [ [ FFCellFindUser alloc ] initWithStyle : reuseIdentifier UITableViewCellStyleDefault : CellIdentifier ] ;
    }
    
    
       if (! isFiltered ) {
        
        
        PFObject * object = [ allObjects objectAtIndex : indexPath.row ] ;
        NSString * str = [object objectForKey : FF_USER_NOMECOGNOME ] ;

        cell.FFLabelCell_NomeCognome.text = str ;
        
        
        cell.FFIMGCell_FotoProfilo.image = [ UIImage imageNamed : @ " FFIMG_Camera "] ;
        [ cell.FFIMGCell_FotoProfilo.layer setMasksToBounds : YES] ;
        [ cell.FFIMGCell_FotoProfilo.layer setCornerRadius : 22.5f ] ;
        cell.FFIMGCell_FotoProfilo.file = [object objectForKey : FF_USER_FOTOPROFILO ] ;
        [ cell.FFIMGCell_FotoProfilo loadInBackground ] ;
        
       / / Cell.FFUserButton.tag = indexPath.row ;
       / / [ Cell.FFUserButton addTarget : self action: @ selector ( FFInviaRichiestaAmicizia :)
         / / ForControlEvents : UIControlEventTouchUpInside ] ;
          
           

/ / HERE I AM RECALLING THE BOOLEAN VALUE CLASS FRIENDSHIPS
         
  if ( [ [object objectForKey : @ " RICHIESTA_IN_ATTESA "] boolValue ] ) {
               
               [ cell.FFUserButton setHidden : YES] ;
           Else { }
               [ cell.FFUserButton setHidden : NO] ;
           }

}

You're approaching your problem in the wrong way by using 您通过使用错误的方式来解决问题

if ( [ [object objectForKey : @ " RICHIESTA_IN_ATTESA "] boolValue ] )

because that means that the users need to know if they are the friend of the current user. 因为这意味着用户需要知道他们是否是当前用户的朋友。 This is the wrong way round. 这是错误的方法。 You current user should have a list of its current friends (either an array of object ids or relationships in Parse). 您当前的用户应具有其当前好友的列表(对象ID数组或Parse中的关系)。 Your table view controller should also have access to the current user. 您的表视图控制器还应该有权访问当前用户。 Then, you write the code to show / hide the buttons as: 然后,编写代码以显示/隐藏按钮,如下所示:

Note: currentUserFriends is an array of user object ids built from the relationship / information on the current user 注意: currentUserFriends是根据当前用户的关系/信息构建的用户对象ID的数组

[cell.FFUserButton setHidden:([currentUserFriends containsObject: object.objectId])];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM