6

我有一个 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]; 
}
4

1 回答 1

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];
}
于 2013-01-30T14:00:17.503 回答