gpt4 book ai didi

ios - UIActivityIndi​​catorView+AFNetworking 或 UIProgressView+AFNetworking

转载 作者:行者123 更新时间:2023-11-29 12:36:46 30 4
gpt4 key购买 nike

你能帮我理解如何使用 UIActivityIndi​​catorView+AFNetworkingUIProgressView+AFNetworking 吗?我是否需要再创建一个 UIViewController,如果是,我需要在哪里实现它?我发现我需要使用 setProgressWithUploadProgressOfOperationsetAnimatingWithStateOfOperation,但我仍然需要一个示例。

我的代码是:

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

最佳答案

我想,您想在加载操作时显示 UIActivityIndi​​cator。所以你必须做这样的事情:

// 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 - UIActivityIndi​​catorView+AFNetworking 或 UIProgressView+AFNetworking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26099714/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com