AFNetworking冻结我的GUI

时间:2014-08-06 07:07:04

标签: ios uitableview user-interface afnetworking-2

如果加载视图,我需要加载我的UItableView与afnetworking,但GUI冻结

完成下载后 - gui unfreeze

我的代码

- (void)viewDidLoad {
    [super viewDidLoad];

    if (![self isExistsClub]) {

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
            [self loadDataToFile];
        });



        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadClubsData:) name:@"loadClubsData" object:nil];
    }
}

- (void)loadClubsData:(NSNotification *)not {

    if ([[not object] boolValue]) {

        [_clubsTableView reloadData];

    }   
}

NSURL *url = [NSURL URLWithString:@"somesite/api/clubs.json"];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

operation.responseSerializer.acceptableContentTypes = [operation.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id clubsData) {

    /* some code parse JSON */

    NSNumber *clubLoad = [NSNumber numberWithBool:YES];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"loadClubsData" object:clubLoad];


}];

[operation start];

1 个答案:

答案 0 :(得分:0)

我重新翻译了解析课程并且工作正确