这是我用afnetworking加载我的json的方法:
-(void) connectPhp {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:@"http://XXXXXXXXXXXXX.php" parameters:nil success:^(AFHTTPRequestOperation *operation, NSArray * responseObject) {
i=0;
test = (NSDictionary *)responseObject;
compteur =test[@"images"][@"items"];
total=[compteur count];
NSLog(@"%d TOTO", total);
// AFFICHER LE TOTAL D'URL DANS TOTAL NSLog(@"%d", total);
NSLog(@"%@", test[@"images"][@"items"][i][@"title"]);
NSString *urltest = test[@"images"][@"items"][i][@"url"];
self.label.text = test[@"images"][@"items"][i][@"title"];
url = [NSURL URLWithString:urltest];
data = [NSData dataWithContentsOfURL:url];
img = [[UIImage alloc] initWithData:data];
//Je stocke le total d'images
totalImg = [NSString stringWithFormat:@"%d", total];
//Je stocke l'ID de l'image
idImg = [NSString stringWithFormat:@"%d", i+1];
NSLog(@"%@", idImg);
//je donne au compteur la valeur idImg
self.compteurID.text=idImg;
self.compteurTotal.text=totalImg;
if (total<9){
[self.pageControl setNumberOfPages:total];
[self.pageControl setCurrentPage:i];
}
else if (total>9){
[self.pageControl setNumberOfPages:10];
NSLog(@"ICI TOTAL>10");
}
}
failure:nil];
}
这是我在拖动时切换图像的方法:
-(void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (self.scrollView.contentOffset.x<-20){
if (i==0){[self resizeImages];}
else{
i--;
[self resizeImages];
}
}
else if ((self.scrollView.bounds.size.width)-(self.scrollView.contentOffset.x)==25){
if (i==(total)-1){i=0;}
i++;
[self resizeImages];
}
else if (self.scrollView.contentOffset.x>(self.imgView.frame.size.width)/3){
if (i==(total)-1){i=0;}
i++;
[self resizeImages];
}
}
有效。 当我拖动时,我在我的json中加载下一个图像的url。有用。 但是,我想在拖动时以及下载图像时显示一个活动指示器。我怎么能这样做?
答案 0 :(得分:1)
UIActivityIndicatorView
并启动动画。removeFromSuperview
消息。