Problems with MBProgressHUD

Discussion in 'iOS Programming' started by joak, Mar 26, 2014.

  1. joak macrumors newbie

    Joined:
    Mar 7, 2014
    #1
    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];    });
    }
    
     
  2. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #2
    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);
    }
    
    
     
  3. joak thread starter macrumors newbie

    Joined:
    Mar 7, 2014
    #3
    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
     
  4. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #4
    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
     
  5. joak thread starter macrumors newbie

    Joined:
    Mar 7, 2014
    #5
    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?
     
  6. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #6
    I don't believe so. They are probably executing on the main thread which blocks the UI from updating until the task is done
     

Share This Page