Parse.com:在TableViewCell中检索布尔值
Parse.com我在我的项目中使用。 在我的视图控制器中,我有一个搜索栏,它从一个类中获取数据,该类与我需要的布尔值不同。
简而言之,每个单元格都包含一个按钮,当按下该按钮时,它会创建一个布尔值,正如我上面所说的那样,是另一个与主查询不同的类。
为了帮助您了解:
搜索栏从“_USER”类中获取数据,其中所有驻留注册用户应用程序
该按钮用于在“朋友”类中创建一个布尔值
我无法连接这两个动作……
我做了一些测试,但我无法得到我想要的结果..你能解释一下我怎么做才能解决这个问题吗? 我不明白我的错误在哪里
这里我展示了查询和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] ; } }
您正在以错误的方式使用您的问题
if ( [ [object objectForKey : @ " RICHIESTA_IN_ATTESA "] boolValue ] )
因为这意味着用户需要知道他们是否是当前用户的朋友。 这是错误的方式。 您当前的用户应该有一个当前朋友的列表(Parse中的对象ID或关系数组)。 您的表视图控制器也应该有权访问当前用户。 然后,您编写代码以显示/隐藏按钮:
注意: currentUserFriends
是根据当前用户的关系/信息构建的用户对象ID数组
[cell.FFUserButton setHidden:([currentUserFriends containsObject: object.objectId])];