0

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];
 }
soumya
  • 3,801
  • 9
  • 35
  • 69
  • in downloading time , user not go to back or else,... – Anbu.Karthik Nov 11 '14 at 05:03
  • User should not go back nor perform some actions like button actions like login, play etc – soumya Nov 11 '14 at 05:04
  • You need to show *some* code - what have you tried? In essence you just need to set your UI controls to `enabled=NO` until loading has finished. – Paulw11 Nov 11 '14 at 05:06
  • I saw this really nice method the other day: http://stackoverflow.com/questions/5551432/dont-allow-user-interaction-when-activity-indicator-view-is-visible/16609327#16609327 – Zhang Nov 11 '14 at 05:13

2 Answers2

1

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];
}
Vipul
  • 130
  • 8
  • You can use this tutorial for [MBProgressHud](http://www.iossdktutorials.com/ios-sdk-uiactivityindicatorview-and-mbprogresshud/) – Vipul Nov 11 '14 at 05:22
1

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

    }
   });
 }];
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143