Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MBProgressHUD blocks user interaction with a tableview

I have a uitableview which loads data from internet and during this period im displaying MBProgressHUD. But the problem is the user cannot touch anything including previous page button before the table loads. Here is my codein two different classes:

//PROBLEM METHOD 1
- (void)viewDidLoad
{
    [super viewDidLoad];
    [tableEtkinlikler reloadData];
    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.labelText = @"Açılıyor...";
    HUD.userInteractionEnabled = NO;

    [self performSelector:@selector(loadEtkinliklerTitlesAndImages) withObject:nil afterDelay:0];

    tableEtkinlikler.dataSource = self;
    tableEtkinlikler.delegate = self;
}

I have the same problem with a button also..In it im loading data from internet..

//PROBLEM METHOD 2
- (IBAction)AktivitelerButtonClicked:(UIButton *)sender
{
    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.labelText = @"Açılıyor...";
    HUD.userInteractionEnabled = NO;
    [self performSelector:@selector(openAktivitelerWindow) withObject:nil afterDelay:0]; 
}
like image 976
birdcage Avatar asked Jan 30 '13 13:01

birdcage


1 Answers

I believe for me that is the point of MBProgressHUD , it gives you the opportunity show a HUD while your tasks are completed, once your tasks are completed you dismiss it so user can interact with completed data.

However In some cases loading data takes so long so you might want to let the user decide to continue , choose another option or just simply go back

in your code this HUD.userInteractionEnabled = NO; should work but problem might be that showHUDAddedTo:self.view you do not use the highest view possible in the view hierarchy.

Try to use this:

- (IBAction)showSimple:(id)sender {
    // The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];
    HUD.userInteractionEnabled = NO;
    // 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(loadEtkinliklerTitlesAndImages) onTarget:self withObject:nil animated:YES];
}
like image 74
u.gen Avatar answered Nov 04 '22 06:11

u.gen