0

我有这种方法可以到达 Web 服务并带回 JSON。该方法运行良好,问题是我想要一个旋转条进度,而该方法还没有带来任何东西。

-(void)loadJson{



    NSString *urlString = [NSString stringWithFormat:@"%@",kGetURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];

    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

        self.json = JSON;
        [myTableView reloadData];

    } failure:^(NSURLRequest *request , NSURLResponse *response , NSError *error , id JSON){

        NSLog(@"Failed: %@",[error localizedDescription]);

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                        message:@"didn't reach the server"
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];



    }];

    [operation start];


}

谢谢你。

4

1 回答 1

1

创建一个 UIActivityIndi​​catorView,这里称为 mySpinner,并将其添加到屏幕上。然后:

-(void)loadJson{

    NSString *urlString = [NSString stringWithFormat:@"%@",kGetURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];

    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        [mySpinner stopAnimating];    

        self.json = JSON;
        [myTableView reloadData];

    } failure:^(NSURLRequest *request , NSURLResponse *response , NSError *error , id JSON){
        [mySpinner stopAnimating];

        NSLog(@"Failed: %@",[error localizedDescription]);

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                        message:@"didn't reach the server"
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];



    }];

    mySpinner.hidesWhenStopped = YES;
    [mySpinner startAnimating];

    [operation start];


}
于 2013-05-24T22:28:24.007 回答