我正在使用这种方法:
- (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];
}
}
}];
}
它工作正常,但直到第二次,我的意思是,当我第一次调试它时,它会转到“Inicio ConexionInicio:...”,它会下降,即:我调用[reload:nil]
,ViewDidLoad
所以在它之后我立即需要数组“ reload" 加载,但没有发生,reload 将数组返回给我,直到ViewDidLoad
完成,我要问的是:有谁知道 AFNetworking 是否总是在第二次之前执行该方法?,让我告诉你什么是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);
}
}];
}
第一次加载失败[[APIClient sharedClient] getPath:@"/WebConnection/ServletInicioJSON" parameters:nil success:^(AFHTTPRequestOperation *operation, id JSON)]
然后退出