Question

I am trying to implement the SVProgressHUD progress activity indicator. I copied the class from the [demo].1

My app loads up but the activity indicator doesn't show up. This is my first time trying to use one of these, so any help would be appreciated.

Here is the code:

#import "SVProgressHUD.h"

@implementation QuotesAppDelegate

- (void)startLoading 
{
    //call this in your app delegate instead of setting window.rootViewController to your main view controller
    //you can show a UIActivityIndiocatorView here or something if you like
    [SVProgressHUD show];
    [self performSelectorInBackground:@selector(loadInBackground) withObject:nil];
}

- (void)loadInBackground
{ 
    //do your loading here
    //this is in the background, so don't try to access any UI elements
    [self populateFromDatabase];

    [SVProgressHUD dismiss];

    [self performSelectorOnMainThread:@selector(finishedLoading) withObject:nil waitUntilDone:NO];
}

- (void)finishedLoading
{
    //back on the main thread now, it's safe to show your view controller
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
}


- (void)applicationDidFinishLaunching:(UIApplication *)application {

    [self copyDatabaseIfNeeded];

    [self startLoading];
}
Was it helpful?

Solution

First of all you were not adding your SVProgressHUD to the view.

If your class inherited from UIViewController then [self.view addSubview:]; or if your class is simple UIView then [self addSubView:];

I do not understand your requirement but as far as i can understand through your code that you are showing [SVProgressHUD show]; in your startLoading method and then you are calling loadInBackground method in that method where you are hiding your hud using [SVProgressHUD dismiss];

I will suggest you to trace it by using breakpoint and figure it out.

OTHER TIPS

For anyone else having a similar problem, this can also happen because you have a long loop or a piece of code that takes a long time to execute. If this happens, your progress bar wont be shown until after the loop, which kind of defeats the purpose.

To solve this issue you need to you this:

- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg

Basically your code would look something like this:

- (IBAction)submitPost:(id)sender {
    //now we show the loading bar and submit the comment
    [SVProgressHUD showWithStatus:@"Submitting post" maskType:SVProgressHUDMaskTypeGradient];
    SEL aSelector = @selector(submitDataOfPost);
    [self performSelectorInBackground:aSelector withObject:sender];
}

This will basically load the progress bar, and in a background thread, the method you want to execute will be called. This makes sure that the UI is updated (shows the progress hud) at the same time that your code is executed.

I had the same problem. When I changed a version of SVProgressHUD to the later one the problem disappeared. My current version supports ARC.

=>

(IBAction)fetchData:(id)sender 
    {    

            [SVProgressHUD showWithStatus:@"Loading..." maskType:SVProgressHUDMaskTypeGradient];
            [self performSelectorOnMainThread:@selector(getDataFromSomeWhere) withObject:nil waitUntilDone:NO];
        }

=>

(void)getDataFromSomeWhere
{

      //Do your data populating here. and dismiss the ProgressHud.
     [SVProgressHUD dismiss];

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