MBProgressHUD阻止用户与tableview的交互

时间:2013-01-30 13:03:08

标签: ios xcode uitableview mbprogresshud

我有一个uitableview,可以从互联网上加载数据,在此期间我会显示MBProgressHUD。但问题是用户在加载表之前无法触摸包括上一页按钮在内的任何内容。这是我的代码,有两个不同的类:

//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;
}

我的按钮也有同样的问题..在它加载来自互联网的数据..

//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]; 
}

1 个答案:

答案 0 :(得分:10)

我相信MBProgressHUD这一点,它为您提供了在完成任务时展示HUD的机会,一旦您的任务完成,您将其解除,以便用户可以与已完成的数据进行交互。

然而,在某些情况下,加载数据需要很长时间,因此您可能希望让用户决定继续,选择其他选项或只是简单地返回

在您的代码中,此HUD.userInteractionEnabled = NO;应该有效,但问题可能是showHUDAddedTo:self.view您没有在视图层次结构中使用可能的最高视图。

尝试使用它:

- (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];
}