I have found a way to queue JSON parsing operation to wait complete data parse, and this is the code:
- (void)LoadParse { // this method is called by a UIButton
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5.0];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
// PARSING SUCCESS CODE
NSLog(@"operation completed"); <--- END OPERATION
[self anotherMethod]; <--- CALL METHOD AFTER OPERATION IS FINISHED
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON {
// PARSING FAILURE CODE
}];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:operation]; <--- START OPERATION
// I NEED TO SHOW A SORT OF INDICATOR TO ADVERT USER THAT OPERATION ARE STILL LOADING
// EXAMPLE: [DejalBezelActivityView activityViewForView:self.view withLabel:@"LOADING..."].showNetworkActivityIndicator = YES;
[queue waitUntilAllOperationsAreFinished];
}
The queue works perfectly: app waits the end of parsing operation, then it calls anotherMethod. But I need to show a sort of activityView to advert user when there is still loading operation: as u can see I've tried to add it between addOperation and waitUntilAllOperationsAreFinished but I cant see anything. IS IT THE RIGHT WAY? So, where is the RIGHT place to put activityView code to view it Until All Operations Are Finished, or another way to do that trick? Thanks!