0

iOSアプリでjsonデータをプルする前にalertviewインジケータを呼び出そうとしていますが、データがすでにロードされているかどうかを確認してからalertviewインジケータを消す方法がわかりません。今のところ常にすべてのデータがすでに読み込まれている場合でも表示されます。ここに私のコードがあります:

//
//  Firstcine.m
//  
//
//  
//

#import "Firstcine.h"

@interface Firstcine (){

UIAlertView *loading;

}

@end

@implementation Firstcine

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];


// Loading Show Alert View...
loading = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." 
delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView 
alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[loading addSubview:progress];
[progress startAnimating];
[loading show];


// dis play all  data after first  loaded


NSURL *url = [NSURL URLWithString:@"http://localhost/App/first.php"];

NSData *jsonData = [NSData dataWithContentsOfURL:url];

NSArray *json = [NSJSONSerialization JSONObjectWithData:
jsonData  options:NSJSONReadingAllowFragments error:nil];



// Do any additional setup after loading the view.

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_tile.png"]];




NSDictionary *dict = [json objectAtIndex:0];
name.text = [dict valueForKey:@"name"];
time.text = [dict valueForKey:@"time"];
date.text = [dict valueForKey:@"date"];
price.text = [dict valueForKey:@"price"];

// then display photo

UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(75, 87, 150,200)];
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[dict  valueForKey:@"photo" ]]]];

[self.view addSubview:image];










}



- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
4

1 に答える 1