Calling queryTask in a loop

Discussion created by miribsystematics-co-il-esridist Employee on Oct 27, 2011
Latest reply on Oct 31, 2011 by DGoyal-esristaff

I'm trying to call queryTask in a loop but it looks like it refers only to the last call, i.e. it enters to didExecuteWithFeatureSetResult only in the last call).

Is there a way to force it to work asynchronously?

Here is the chunk of code I'm using:

  for (NSDictionary *r in res)
   NSString *layer = [r objectForKey:@"layerId"]  ;
   NSString *objectsID = @"";
   NSArray *features = [r objectForKey:@"features"];
   for (NSDictionary *feature in features) {
    NSString *objectID = [feature objectForKey:@"OBJECTID"];
    objectsID = [NSString stringWithFormat:@"%@ , %@",objectsID, objectID];
   //Remove first ,
   objectsID = [objectsID substringFromIndex:2];

   //objectsID = @"OBJECTID IN (";
   objectsID = [NSString stringWithFormat:@"%@  %@", @"OBJECTID IN (", objectsID];
   objectsID = [NSString stringWithFormat:@"%@ )",objectsID];

   NSString *waterLayerURL =[NSString stringWithFormat:@"%@%@",@"http://mnatania10/ArcGIS/rest/services/GeneralView/MapServer/", layer];
   //set up query task against layer, specify the delegate
   self.queryTask = [AGSQueryTask queryTaskWithURL:[NSURL URLWithString:waterLayerURL]];
   self.queryTask.delegate = self;
   //return all fields in query
   self.query.where = objectsID;
   NSLog(@"name : %@", self.query.where);
   [self.queryTask executeWithQuery:self.query];

Thanks a lot,