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