Search code examples
iosobjective-cpositionuiactivityindicatorviewmbprogresshud

IOS MBProgressHUD display location error(it is not center,the loading display on left top.)


I use MBProgressHUD showWhileExecuting to query some data from network,but the MBProgressHUD is not center sometimes

enter image description here

on pictures(red number):

loading displayed on left top and the backgound displayed at center.

1.loading display is not on background of MBProgressHUD 2.just show a background that doesn't contain loading

-(void)viewDidLoad
{
    //other code ...

    mb = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    // --> i try which causes also an error
    //[[MBProgressHUD alloc] initWithWindow:self.view.window]; 
    // --> error too
    //[[MBProgressHUD alloc] initWithView:self.view];
    mb.labelText = @"loding city...";

    [self.navigationController.view addSubview:mb];
    [mb showWhileExecuting:@selector(queryCity:) 
                  onTarget:self 
                withObject:[NSNumber numberWithInt:1] 
             animated:YES];
}

-(void)queryCity:(NSNumber*)flag
{
    //query some data from network.
}

Solution

  • i find this problem. when MBProgressHUD cleanup it will lost rect.

    - (void)cleanUp {
    taskInProgress = NO;
        //changed by zt9788 2012-12-26
        //comment this line to fix it.
    //self.indicator = nil;
    #if !__has_feature(objc_arc)
    [targetForExecution release];
    [objectForExecution release];
    #else
    targetForExecution = nil;
    objectForExecution = nil;
    #endif
    [self hide:useAnimation];
    

    }