AFHTTPRequestOperationManager网络请求的时候添加一个菊花

问:

Can you help me to understand, how to use UIActivityIndicatorView+AFNetworking or UIProgressView+AFNetworking. Do I need to create one more UIViewController and if yes, where do I need to implement it? have found out that I need to use setProgressWithUploadProgressOfOperation or setAnimatingWithStateOfOperation, but I still need an example.

my code is:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:@"" forHTTPHeaderField:@""];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager GET:@"blablabla" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

    // 3
    //[self.view setAnimatingWithStateOfOperation:operation];
    NSLog(@"JSON: %@", responseObject);
    NSArray *carsList = responseObject[@"data"];
    [self showStream:carsList];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    // 4
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                        message:[error localizedDescription]
                                                       delegate:nil
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];
    [alertView show];
}];




答:

I guess, you want to show UIActivityIndicator while operation is loading. So you have to do something like this:

// your code

AFHTTPRequestOperation *operation = [manager GET:@"blablabla" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    // even more code
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // and here
}];

UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] init];
indicatorView.frame = /*calculate frame here*/;
[self.view addSubView:indicatorView];
[indicatorView setAnimatingWithStateOfOperation:operation];




郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。