【发布时间】:2013-11-28 13:06:31
【问题描述】:
大家好,我有一个非常愚蠢的问题,但我想确保我完全理解这件事......
有人可以'用简单的语言解释他们在做什么这个布尔方法吗?
- (BOOL) AssignedGoPointToPost : ( PFObject *) { GoPointAssigned
for ( PFObject * goPoint in UpVoteCurrentUser ) {
if ( [[[ goPoint objectForKey : @ " Oggetto_Votato "] objectId ] isEqualToString : GoPointAssigned.objectId ]) {
return YES ;
}
}
return NO;
}
我感兴趣的 BOOL 附带的查询是这样的
- (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 的数据浏览器中,并从 Medal Medal_Blu 更改图像...
您看到的代码调用了我在下面显示的两种操作方法。我们说这些功能运行良好,但是当您按下“赞”按钮时,数据和图像的更改不是同时发生的...经常甚至收到命令并且不保存甚至更新数据......我不明白我错在哪里。我正在尝试以 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 ] ;
}
} ] ;
}
【问题讨论】:
-
你能分享你想要做什么吗?您做了什么,您希望我们为您提供什么帮助?
标签: ios boolean parse-platform