码迷,mamicode.com
首页 > Web开发 > 详细

AFHTTPRequestOperationManager当一个网络请求加入菊花

时间:2015-06-25 19:26:01      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

问:

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];




AFHTTPRequestOperationManager当一个网络请求加入菊花

标签:

原文地址:http://www.cnblogs.com/bhlsheji/p/4600414.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!