我有这个方法到达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];
}
谢谢。
答案 0 :(得分:1)
创建一个名为mySpinner的UIActivityIndicatorView,并将其添加到屏幕上。然后:
-(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];
}