作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
你能帮我理解如何使用 UIActivityIndicatorView+AFNetworking
或 UIProgressView+AFNetworking
吗?我是否需要再创建一个 UIViewController
,如果是,我需要在哪里实现它?我发现我需要使用 setProgressWithUploadProgressOfOperation
或 setAnimatingWithStateOfOperation
,但我仍然需要一个示例。
我的代码是:
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];
}];
最佳答案
我想,您想在加载操作时显示 UIActivityIndicator。所以你必须做这样的事情:
// 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];
关于ios - UIActivityIndicatorView+AFNetworking 或 UIProgressView+AFNetworking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26099714/
我是一名优秀的程序员,十分优秀!