Disabling UI interaction of iPad till the data is downloading on main thread in backend

75 views Asked by At

I want to Disable UI interaction of iPad till the data is downloading on main thread in backend using Blocks

I m downloading the images at loading time

-(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];
 }
2

There are 2 answers

1
Anbu.Karthik On BEST ANSWER

if use entire application call

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

after downloading completion

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

another choice

 [self.view setUserInteractionEnabled:NO];  

after the completion

  [self.view setUserInteractionEnabled:YES]; 

one more choice

  self.navigationController.navigationBar.userInteractionEnabled=NO;
  // perform other events also userInteractionEnabled=NO; 

after the completion

  self.navigationController.navigationBar.userInteractionEnabled=YES;
  // perform other events also userInteractionEnabled=NO; 

in your question

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

    }
   });
 }];
}
1
Vipul On

You can use MBProgressHud for this. You need to add MBProgressHUD files into project.

        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];
}