MBProgressHUD阻止用户与tableview的交互

bir*_*age 6 xcode uitableview ios 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;
}
Run Code Online (Sandbox Code Playgroud)

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

//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]; 
}
Run Code Online (Sandbox Code Playgroud)

u.g*_*gen 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];
}
Run Code Online (Sandbox Code Playgroud)