0

I'm using this method:

- (void)reload:(id)sender {
    mutableImagenes=[[NSMutableArray alloc]init];
     NSMutableArray *arrayImagenes=[[NSMutableArray alloc] init];
    [Inicio ConexionInicio:^(NSArray *imagenesArray, NSError *error) {
        if (error) {
            [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:[error localizedDescription] delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK", nil), nil] show];
        } else {
            _ArrayInicio = imagenesArray;
            for(Inicio *i in _ArrayInicio){
                [mutableImagenes addObject:i];
            }
        }
    }];
}

It works fine BUT until the second time, I mean, when I am debugging it the first time that goes to "Inicio ConexionInicio:..." it falls, i.e.: i call [reload:nil] in ViewDidLoad, so after it I inmediately needs the array that "reload" loads, but that not happens, reload returns me the array until ViewDidLoad finish and what I am asking is: Does anyone knows if AFNetworking always do that method until the second time?, let me show you what is ConexionInicio:

+ (void)ConexionInicio:(void (^)(NSArray *imagenesArray, NSError *error))block {
    [[APIClient sharedClient] getPath:@"/WebConnection/ServletInicioJSON" parameters:nil success:^(AFHTTPRequestOperation *operation, id JSON) {
        NSArray *imagenesFromResponse = [JSON valueForKeyPath:@"Inicio"];
        NSMutableArray *mutableImagenes = [NSMutableArray arrayWithCapacity:[imagenesFromResponse count]];
        for (NSDictionary *attributes in imagenesFromResponse) {
            Inicio *i = [[Inicio alloc] initWithAttributes:attributes];
            [mutableImagenes addObject:i];
        }

        if (block) {
            block([NSArray arrayWithArray:mutableImagenes], nil);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (block) {
            block([NSArray array], error);
        }
    }];
}

The first time that loads it fails in [[APIClient sharedClient] getPath:@"/WebConnection/ServletInicioJSON" parameters:nil success:^(AFHTTPRequestOperation *operation, id JSON)] and then quits

Firo
  • 15,448
  • 3
  • 54
  • 74
iPive
  • 1
  • 1
  • 2
    I would clean up your question if you expect anyone to answer.....it is highly unreadable at the moment. :/ – Gwynant Jones Feb 01 '13 at 15:24
  • Use directly the AFJSONRequestOperation class: http://afnetworking.github.com/AFNetworking/Classes/AFJSONRequestOperation.html. Actually there is a JSON example at the top: https://github.com/AFNetworking/AFNetworking – Resh32 Feb 01 '13 at 16:32
  • Please use sentences. I am sure that your native language uses sentences as effectively as english. I am guessing that you want the reload method to return only after it has loaded data from your HTTP request. In order to do this, you will have to modify ConexionInicio to use `AFRequestOperation` (or `AFJSONRequestOperation` as suggested by Resh32 ). You can then call `-waitUntilFinished` on the operation object after adding it to the queue. See [here](https://github.com/AFNetworking/AFNetworking/issues/23) and [here](http://stackoverflow.com/questions/7969865) for info. – Spathi Wankenstein Feb 02 '13 at 00:58

0 Answers0