向 JSON 网络服务发送空值或无值会检索 faliure



我有 2 个网络服务,其中检索所有图像和其他从 Web 服务中检索过滤的图像。
当应用程序加载时,调用检索所有图像的Web服务。当用户应用过滤器时,它会检索过滤后的图像。但我面临的问题是:

问题陈述:
当用户选择至少一个过滤器时,它工作正常。但是当用户取消选择(意味着没有选择任何过滤器)时,它会失败。我的 Web 服务编码方式是,当没有传递任何参数时,它应该返回所有图像,但它没有。我希望它再次加载所有图像网络服务。

带有代码说明:

[operation GET:@"stock_search" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
       //  operation is AFHTTPRequestOperationManager
         NSMutableArray *temGalArray = [responseObject objectForKey:@"data"];
         [imageArray removeAllObjects];
         for (NSDictionary *myDict in temGalArray)
         {      
             id object = [myDict objectForKey:@"square_image"];
             if ([myDict objectForKey:@"square_image"]!=[NSNull null])
             {
                 [imageArray addObject:myDict]; //this works fine
             }
             else if([object isEqual:[NSNull null]])
             {
                 [self getGalleryFromWeb]; //***PROBLEM IS HERE***
                 //1: This condition is never true
                 //2: Self.getGalleryFromWeb is the webserivce that get 
                 //   all the images from web. There is no issue in that webservice
             }
         }
         [galleryView reloadData];
     }
           //It always loads failure code below
           failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Applying Filters"
                                                             message:@"Check Your Internet Connection"
                                                            delegate:nil
                                                   cancelButtonTitle:@"OK"
                                                   otherButtonTitles:nil];
         [alertView show];
     }];
}

那么我应该在"else if"下写什么,以便在没有选择过滤器值时,它会再次加载所有图像,就像加载应用程序一样。我希望我已经解决了我的问题,因为这是我的第一个问题,所以如果我错过了什么,我准备提供。

当您当时获得选择时,请检查过滤后的数组计数,如果它是>0,则不要调用任何 Web 服务。这样,您之前加载的图像将不会刷新。仅当数组计数大于>0 时调用过滤的 Web 服务,然后重新加载数据。

最新更新