Question

I'm making an iOS 6 program which downloads JSON data from a website and displays it in a table view. I ask the user to enter an address and then hit a button. That button should display an alert view and then download the data.

My problem is that the alert view doesn't show up until the download is finished. I also tried creating the alert view in the download method but I have the same problem. Is it possible to do what I want ? If yes, am I doing something wrong ?

Thanks for your help.

Was it helpful?

Solution 2

I found a way to resolve my problem, I just had to change the priority of events using the code :

        /*
          Setup indicator and show it
        */


    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        /*
          Download the data
        */

        dispatch_async(dispatch_get_main_queue(), ^{
            /*
          Remove the Alert View
            */

    });
});

Thanks for helping me.

OTHER TIPS

You will get the Output as : Loading....

Firstly import MBProgressHUD.h and MBProgressHUD.m from here

Then write the following code in ViewController.h

#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"

@interface ViewController : UIViewController
{

   MBProgressHUD *HUD;

}

Then Write the following methods in ViewController.m

//To Add Loading View on current View

- (void)showOnWindow {

// The hud will disable all input on the view
    HUD = [[MBProgressHUD alloc] initWithView:self.view.window];

// Add HUD to screen 

    [self.view addSubview:HUD]; 

// Register for HUD callbacks so we can remove it from the window at the right time

    HUD.labelText = @"Loading...";

// Show the HUD while the provided method executes in a new thread

   [HUD showWhileExecuting:@selector(yourtask) onTarget:self withObject:nil animated:YES];
}

Then,

// To Remove the Loading View from current view

- (void)removeOnWindow {

// Do something useful in here instead of sleeping ...

   [HUD removeFromSuperview];

}

Now, Call the methods onClick events....

// Add Loading View

- (IBAction)SetSignIn:(id)sender {

     [self showOnWindow];

}

// yourtask method

-(void)yourtask {

   @try{

     // Do Whatever you want
     // You can call webservices also

  }
  @catch (NSException *e) {

    NSLog(@"Error");

  }

  @finally{

  [self removeOnWindow];  

  }

}

Thanks jrock007

it's works :

I found a way to resolve my problem, I just had to change the priority of events using the code :

    /*
      Setup indicator and show it
    */


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    /*
      Download the data
    */

    dispatch_async(dispatch_get_main_queue(), ^{
        /*
      Remove the Alert View
        */

});

});

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top