Search code examples
iphoneobjective-cmbprogresshud

Change MBProgressHUD selector


I use this code to show MBProgress

- (void)showSimple {
    // The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];


    // Regiser for HUD callbacks so we can remove it from the window at the right time
    HUD.delegate = self;

    // Show the HUD while the provided method executes in a new thread
    [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];}

- (void)myTask {
    // Do something usefull in here instead of sleeping ...
    sleep(3);
}

I want the activity indicator displays when not running MyTask but this method

- (void)request:(FBRequest *)request didLoad:(id)result {
}

i tried to change

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

to

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

or

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

but it does not work


Solution

  • I actually prefer SVProgressHUD over MGProgressHUD because it's nicer, but whatever. Back to your problem.

    The problem with what you're doing is you're not taking into account for the arguments of your method. As long as your method doesn't need the arguments, you could change your selector to include two empty arguments:

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