1

您能幫我瞭解,如何使用UIActivityIndicatorView+AFNetworkingUIProgressView+AFNetworking。我是否需要再創建一個UIViewController,如果是,我需要在哪裏實施?發現我需要使用setProgressWithUploadProgressOfOperationsetAnimatingWithStateOfOperation,但我仍然需要一個示例。UIActivityIndi​​catorView + AFNetworking或UIProgressView + AFNetworking

我的代碼是:

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

回答

1

我想,你想展示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]; 
+0

indicatorView沒有顯示, – lhawks 2014-09-30 07:30:36

+1

THX,我添加與框架初始化,一切都很好 – lhawks 2014-09-30 08:27:36