首页 > 代码库 > AFHTTPRequestOperationManager网络请求的时候添加一个菊花
AFHTTPRequestOperationManager网络请求的时候添加一个菊花
问:
Can you help me to understand, how to use UIActivityIndicatorView+AFNetworking
orUIProgressView+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 usesetProgressWithUploadProgressOfOperation
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网络请求的时候添加一个菊花
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。