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

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];
    });
});
于 2013-09-15T13:04:52.100 回答