我有2个网络服务,其中检索所有图像,其他检索来自网络服务的过滤图像。
当应用程序加载它时,调用检索所有图像的Web服务。当用户应用过滤器时,它会检索过滤后的图像。但我面临的问题是:
问题陈述:
当用户选择至少一个过滤器时,它工作正常。但是当用户取消选择(意味着没有选择任何过滤器)时,它就会失败。我的Web服务编码方式是,当没有参数传递时,它应该返回所有图像,但它没有。我希望它再次加载所有图像web-serivce。
使用代码说明:
[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];
}];
}
那么我应该在`其他地方写下'因此,如果没有选择过滤器值,则会再次加载所有图像,就像应用程序加载时一样。我希望我已经解决了我的问题,因为这是我的第一个问题,所以如果有任何我想念的东西,我已准备好提供。
答案 0 :(得分:1)
当您选择时,检查过滤后的阵列计数,如果> 0,则不要调用任何网络服务。 这样,以前加载的图像就不会刷新。只有当数组计数大于> 0时才调用过滤后的webservice,然后重新加载数据。