SVProgressHUD 驳回在自定义类中不起作用



首先,我在一个类文件中添加了一些需要从不同视图控制器调用的函数。对于这些函数,我添加了SVProgressHUD作为预处理,并在所有过程完成后关闭。SVProgressHUD 在进程启动之前正确显示。但经过处理,SVProgressHUD从未被解雇。请让我知道如何解决这个问题。

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

普通.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];
    })
});

相关内容

  • 没有找到相关文章

最新更新