SVProgressHUD拒绝在自定义类中工作

时间:2016-02-16 08:00:35

标签: ios objective-c svprogresshud

首先,我添加了一些需要从一个类文件中的不同ViewControllers调用的函数。对于这些功能,我将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];
}

1 个答案:

答案 0 :(得分:0)

我找到了答案。这样的事情。

[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];
    })
});