如何在拉动json数据之前显示alertview指标(iOS6)

时间:2013-09-15 12:56:51

标签: ios objective-c json

任何人都可以帮我这个代码我试图在我的iOS应用程序中拉json数据之前调用alertview指标但我不知道如何检查数据是否已经加载然后消失了alertview指标,For现在它总是出现甚至所有数据都加载。这是我的代码:

//
//  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

1 个答案:

答案 0 :(得分:0)

你有没有试过这样的东西

UIAlertView *alertView = [[UIAlertView alloc]
                          initWithTitle:@"Configuring Preferences\nPlease Wait..."
                          message:nil
                          delegate:nil
                          cancelButtonTitle:nil
                          otherButtonTitles:nil];

[alertView show];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alertView.bounds.size.width / 2, alertView.bounds.size.height - 50);
[indicator startAnimating];
[alertView addSubview:indicator];


dispatch_queue_t downloadQueue = dispatch_queue_create("saver", NULL);
dispatch_async(downloadQueue, ^{

    // do some heavy lifting ? like a fetch

    dispatch_async(dispatch_get_main_queue(), ^{
        // hide the view
        [alertView dismissWithClickedButtonIndex:0 animated:YES];
    });
});