【问题标题】:Small request for information on the BOOL method关于 BOOL 方法的信息的小请求
【发布时间】: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


【解决方案1】:

有人可以'用简单的术语解释他们在做什么这个布尔值 方法?

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

事实上这不是一个布尔方法,这是一个返回类型为 BOOL(boolean) 的方法。

还有一些编译器错误,首先我会尝试删除。

该方法应如下所示:

- (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 ;

在上面的语句中,goPoint 是一个字典,您在其中根据键“Oggetto_Votato”提取一些对象。然后从您正在访问的对象中访问应该是 NSString 的 objectId。然后从这个字符串中你将它与 GoPointAssigned 的 objectId 进行比较。

如果它们匹配,则返回 YES。这是在循环内部,因此第一个匹配将返回 YES 并且循环将终止。如果没有匹配,则使用 expire 循环并返回 NO。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    相关资源
    最近更新 更多