Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

joak

macrumors newbie
Original poster
Mar 7, 2014
27
0
Hi

I have 5 tasks that I want to show in a MBProgressHUD, but only shows the first and then when the job finish it's hide(this works fine) but i dont'know how can I show the other tasks.

Code:
- (IBAction)btnTest:(id)sender {
    
    JFRed *red = [[JFRed alloc] init];
    red.delegado = self;
    HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.view addSubview:HUD];
	HUD.delegate = self;
	HUD.labelText = @"Ejecutando";
	HUD.detailsLabelText = @"Realizando conexión";
	HUD.square = YES;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        // this will force loading the psc and do a migration
        [red jsonPostRequest:dir tipoId:100 postData:postData]; //My first task
        });
}

//The folowing .... they're the rest task
-(void) terminaDescarga:(NSData *)datos conId:(NSInteger)id httpCodeReturn:(int)code httpStringCodereturn:(NSString*)codestring
{
    [call another method to do a new task] and has this command ..HUD.detailsLabelText = @"Create tables...."; //Doesen't show

    //
    //
    //
    [call another method to do a new task] and has this command ..HUD.detailsLabelText = @"Insert records..."; //Doesen't show

    //
    //
   // remove progress view once we're done.. .this works fine
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:self.view animated:YES];    });
}
 

waterskier2007

macrumors 68000
Jun 19, 2007
1,871
228
Novi, MI
I don't know much about MBProgressHUD, but just FYI, the call to

Code:
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

already adds the created hud to the subviews so you don't need to call

Code:
[self.view addSubview:HUD];

From the github for MBProgressHUD:

Code:
+ (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view animated:(BOOL)animated {
    MBProgressHUD *hud = [[self alloc] initWithView:view];
    [view addSubview:hud];
    [hud show:animated];
    return MB_AUTORELEASE(hud);
}
 

joak

macrumors newbie
Original poster
Mar 7, 2014
27
0
Hello waterskier2007 .... thanks for your comments.


My progress show it ..... but only show the first message ..... the rest of task doesen't show the "text" ... Create tables ... Insert records .... etc etc
 

waterskier2007

macrumors 68000
Jun 19, 2007
1,871
228
Novi, MI
You are probably setting the text yet it is not happening until the main UI is updated on the next cycle, so you never see it. You could try calling

Code:
[HUD performSelectorOnMainThread:@selector(setDetailsLabelText:) withObject:@"Your string here" waitUntilDone:NO];

The reason you may not see the text being updated the way you are doing it is because any tasks that block the main thread from cycling are going to cause the text to not be updated until the thread is freed up to update the UI
 

joak

macrumors newbie
Original poster
Mar 7, 2014
27
0
Yes, I agree .....

I have this instruction

Code:
 HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.view addSubview:HUD];
	HUD.delegate = self;
	HUD.labelText = @"Execute";
	HUD.detailsLabelText = @"First task";
	HUD.square = YES;

dispatch_async(dispatch_get_main_queue(), ^{
        // this will force loading the psc and do a migration
        [red jsonPostRequest:dir tipoId:100 postData:postData]; //JSON Format
        });

The method [red jsonPostRequest] it's the first method to execute .... then this method call another .... I suppose that the methods execute in another thread, correct?
 

waterskier2007

macrumors 68000
Jun 19, 2007
1,871
228
Novi, MI
Yes, I agree .....

I have this instruction

Code:
 HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.view addSubview:HUD];
	HUD.delegate = self;
	HUD.labelText = @"Execute";
	HUD.detailsLabelText = @"First task";
	HUD.square = YES;

dispatch_async(dispatch_get_main_queue(), ^{
        // this will force loading the psc and do a migration
        [red jsonPostRequest:dir tipoId:100 postData:postData]; //JSON Format
        });

The method [red jsonPostRequest] it's the first method to execute .... then this method call another .... I suppose that the methods execute in another thread, correct?

I don't believe so. They are probably executing on the main thread which blocks the UI from updating until the task is done
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.