I've a NSSavePanel instance with a strange behavior: whenever I open it and click on a directory's arrow (the little expand button) it shows an indeterminate loading icon on the left-bottom corner that never ends, and not shows the directory/file tree. An image can see as follow:
In that example, I've clicked in "workspace" directory. And the panel not shows the sub-itens. Even strange is that after I click it again (redrawing the directory) and then click again (re-open the directory), it properly shows all files.
My code is as follows:
// here, I'm creating a web service client, and then calling a method to download a report, and passing the same class as delegate
- (IBAction) generateReport:(id)sender {
// SOME STUFF HERE...
WSClient *client = [[[WSClient alloc] init] initWithDelegate:self];
[client GenerateReport:@"REPORT" withParams:params];
}
- (void) GenerateReport:(NSString *)from withParams:(NSDictionary *)parameters {
// SOME STUFF HERE...
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (!error) {
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
dispatch_async(dispatch_get_main_queue(), ^(void) {
NSLog(@"GenerateReport: [success]");
[self.delegate successHandlerCallback:data from: from];
});
});
}
}];
// this is the callback
- (void) successHandlerCallback:(NSData *) data from: (NSString *) from {
NSString savePath = [savePath stringByReplacingOccurrencesOfString:@"file://" withString:@""];
NSString *filePath = [NSString stringWithFormat:@"%@", savePath];
[data writeToFile:filePath atomically:YES];
}
// and this is to build a panel to let user chose the directory to save the file
- (NSURL *) getDirectoryPath {
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setNameFieldStringValue:[self getDefaultFileName]];
[panel setDirectoryURL:[NSURL fileURLWithPath:[[NSString alloc] initWithFormat:@"%@%@%@", @"/Users/", NSUserName(), @"/Downloads"]]];
if ([panel runModal] != NSFileHandlingPanelOKButton) return nil;
return [panel URL];
}
Can someone give a hint on where I'm missing?
UPDATE: To me, it seens to be something related with dispatch_async!
Thanks in advance!