ios - 禁用 iPad 的 UI 交互,直到数据在后端的主线程上下载

标签 ios objective-c-blocks uiapplicationdelegate

我想禁用 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];
 }

最佳答案

如果使用整个应用程序调用

[[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

    }
   });
 }];
}

关于ios - 禁用 iPad 的 UI 交互,直到数据在后端的主线程上下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26857823/

相关文章:

ios - 应用程序图标在 iPad 中不可见

objective-c - iOS 推送通知/框架问题

javascript - 如何获取ios中UIWebview中的内容

iphone - XCode 4.5 iOS 6.0 模拟器和旋转问题

ios - 按专辑名称获取 ALAssetsGroupAlbum 的海报图像

iOS 未从返回的 block 中看到预期值

iphone - 将参数传递给 block ?

objective-c - iOS Landscape 和 Portrait Delegate 混淆

iphone - 是否需要保存对单例 objective-c 对象的引用,以便在 IOS 应用程序的整个生命周期中保存它?

ios - 当我使用 NSPredicate 为我的 UITableView 过滤我的数组时,应用程序崩溃