Ios Parse.com自定义单元格布尔值

Ios Parse.com自定义单元格布尔值,ios,boolean,parse-platform,Ios,Boolean,Parse Platform,我被布尔显示/隐藏图像困扰了很长时间。图像被放在我的手机里。只需要布尔值。谁能告诉我我做错了什么 PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"]; [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]]; [query findObjectsInBackgroundWithBloc

我被布尔显示/隐藏图像困扰了很长时间。图像被放在我的手机里。只需要布尔值。谁能告诉我我做错了什么

PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"];
    [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
        cell.discounts.hidden =YES;
        }else{
        cell.discounts.hidden =NO;
        }
    }];
编辑:

PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"];
    [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
        cell.discounts.hidden =YES;
        }else{
        cell.discounts.hidden =NO;
        }
    }];

我发现您的代码存在两个问题:

PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"];
    [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
        cell.discounts.hidden =YES;
        }else{
        cell.discounts.hidden =NO;
        }
    }];
  • 由于某种原因,您使用双重编码
    YES
    ,即
    [NSNumber numberWithBool:[NSNumber numberWithBool:YES]
    ,可能不会破坏东西,但会修复它
  • 在块中,您正在检查错误,但没有检查返回的
    对象。如果没有与查询匹配的内容,则数组将返回空,请添加对
    objects.count>0
  • 更改以下内容:-

    PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"];
        [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
            cell.discounts.hidden =YES;
            }else{
            cell.discounts.hidden =NO;
            }
        }];
    
    [NSNumber numberWithBool:[NSNumber numberWithBool:YES]] //No need for this double encoding.
    
    简单搭配[NSNumber numberWithBool:YES]

    PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"];
        [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
            cell.discounts.hidden =YES;
            }else{
            cell.discounts.hidden =NO;
            }
        }];
    

    PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"];
        [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
            cell.discounts.hidden =YES;
            }else{
            cell.discounts.hidden =NO;
            }
        }];
    
    以防在解析时存储图像,并检查图像是否为零或已存储。然后只需简单地调用存储图像的列,而不需要布尔检查条件。这样,您就可以获得对象,并知道应用程序中的哪一行/哪一列要显示/隐藏图像。此外,在该对象中,您将获得图像并将其提供到应用程序中,而无需存储在手机的本地内存中。还有什么事请告诉我

    PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"];
        [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
            cell.discounts.hidden =YES;
            }else{
            cell.discounts.hidden =NO;
            }
        }];
    
    更新:-

    PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"];
        [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
            cell.discounts.hidden =YES;
            }else{
            cell.discounts.hidden =NO;
            }
        }];
    
    因为您将获得对象(数组)

    PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"];
        [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
            cell.discounts.hidden =YES;
            }else{
            cell.discounts.hidden =NO;
            }
        }];
    

    希望这能对您有所帮助。

    Ops,我刚刚忘记删除的第一个内容。但关于第二个,我有一个牢固地放在牢房里的imageview。只想检查布尔值,而不是解析数据库中的图像。你们能告诉我一些你们的流程吗,这样我就可以给出一个合适的答案。这意味着我不明白为什么你要在解析中保留bool,因为你可以在那里存储图像,这样你可以节省本地内存,也可以用于上传部分,你可以使用它让你并行上传,而不会影响用户的UI交互。我有一个自定义单元格填充国家/地区的UITableview。在单元格内,我有一些标签和两个imageview。第一张是使用URL SDWebImage的国家图片,第二张是单元格中的图片。我在我的应用程序中放置了某种“我建议”的图像。我只想根据解析时的布尔T/F隐藏与否。你现在明白我的问题了吗?我已经升级了我的帖子,检查“更新”部分。因此,从parse in objects(array)中得到的结果数组可以使用该数组并从中提取dict,使用该dict,您可以使用objectForKey查看bool是yes还是no。所以在最后隐藏或显示根据是/否。你能检查我的编辑,请?布尔只返回是(1),没有其他返回。
    PFQuery *query = [PFQuery queryWithClassName:@"Parseclass"];
        [query whereKey:@"imagebool" equalTo:[NSNumber numberWithBool:[NSNumber numberWithBool:YES]];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
            cell.discounts.hidden =YES;
            }else{
            cell.discounts.hidden =NO;
            }
        }];