我有一个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];
- }
解决方法
我相信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];
- }