我想禁用iPad的UI交互,直到使用Blocks
在后端的主线程上下载数据我在加载时下载图像
-(void)downLoadImageData{
[self ShowActivityIndicator];
[iOSNetwork getImages:ImageID andEvent:eventID
onCompletion:^(NSString* result,NSError* error)
{
dispatch_async(dispatch_get_main_queue(), ^{
if(error)
{
[self stopFetch:@"Error while Processing"];
}
else
{
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[self stopFetch:result];
}
});
}];
}
-(void) stopFetch:(NSString*) result{
[self hideActivityIndicator];
//after downloading completed
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}
答案 0 :(得分:1)
您可以使用 MBProgressHud 。您需要将MBProgressHUD文件添加到项目中。
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.HUD = [[MBProgressHUD alloc] initWithWindow:appDelegate.window];
[appDelegate.window addSubview:self.HUD];
- (void)showHUDWithText:(NSString *)labelText{
if (_isHUDAlreadyInProgress) {
return;
}
_isHUDAlreadyInProgress = TRUE;
[_HUD.superview bringSubviewToFront:_HUD];
self.HUD.labelFont = [UIFont systemFontOfSize:13.0];
//self.HUD.labelText = labelText;
[self.HUD show:TRUE];
}
- (void)hideHUD{
_isHUDAlreadyInProgress = FALSE;
[self.HUD hide:TRUE];
}
答案 1 :(得分:1)
如果使用整个应用程序调用
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
下载完成后
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
另一种选择
[self.view setUserInteractionEnabled:NO];
完成后
[self.view setUserInteractionEnabled:YES];
还有一个选择
self.navigationController.navigationBar.userInteractionEnabled=NO;
// perform other events also userInteractionEnabled=NO;
完成后
self.navigationController.navigationBar.userInteractionEnabled=YES;
// perform other events also userInteractionEnabled=NO;
在你的问题中
-(void)downLoadImageData{
[self ShowActivityIndicator];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents]; // call here
[iOSNetwork getImages:ImageID andEvent:eventID
onCompletion:^(NSString* result,NSError* error)
{
dispatch_async(dispatch_get_main_queue(), ^{
if(error)
{
[self stopFetch:@"Error while Processing"];
}
else
{
[self stopFetch:result];
// not here
}
});
}];
}