任何人都可以帮我处理这段代码我试图在我的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