SVProgressHUD 关闭在自定义中不起作用 class

SVProgressHUD dismiss not working in custom class

首先,我在一个 class 文件中添加了一些需要从不同 ViewController 调用的函数。对于这些功能,我添加了 SVProgressHUD 作为预处理并在所有过程完成后关闭。 SVProgressHUD 在进程启动之前正确显示。但是在处理之后,SVProgressHUD 根本不会被解雇。请让我知道如何解决该问题。

我已经添加了 [SVProgressHUD dismiss]; 所有过程都已完成。但从未被解雇。

common.m

- (NSDictionary *) loadBlahClass:(NSString *)paramUserId {
    [SVProgressHUD showWithStatus:@"Loading Cards..."];
    __block NSDictionary *jsonResponse;
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.completionQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"application/json"];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];

    NSString *urlStr = [NSString stringWithFormat:@"MY_URL"];

    [manager GET:urlStr parameters:nil
         success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSString *jsonString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
         NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
         jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
         [SVProgressHUD dismiss];
         dispatch_semaphore_signal(semaphore);
     }

         failure:
     ^(AFHTTPRequestOperation *operation, NSError *error) {
         [SVProgressHUD dismiss];
         [self showAlert:APP_NAME alertMessage:[error localizedDescription]];
         dispatch_semaphore_signal(semaphore);
     }];
    [SVProgressHUD dismiss];
    dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
    return jsonResponse;
}

testViewController.m

_allTableData = [[NSMutableArray alloc]init];
NSDictionary *jsonResponse = [commClass loadBlahClass:strUserId];
NSNumber *status = [jsonResponse valueForKey:@"Success"];
NSString *message = [jsonResponse valueForKey:@"Message"];
NSArray *dataArray = [jsonResponse valueForKey:@"lstCC"];

if([status intValue] == 1) {
    for(int i=0; i<[dataArray count]; i++) {
        //working .......
    }

    [_ccTable reloadData];
    [SVProgressHUD dismiss];
} else {
    [commClass showAlert:APP_NAME alertMessage:message];
    [SVProgressHUD dismiss];
}

我找到答案了。诸如此类。

[SVProgressHUD show];
__block BOOL result;
dispatch_async(queue, ^{
    result = [self autanticate];
    NSLog(@"autantication result = %d", result);
    result = [self getCSRFToken];
    NSLog(@"Login success result = %d", result);
    dispatch_async(dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    })
});