Question

I create a tabbar to show mutilple UIViewController but now I don't want to change to other tab when the loading icon is showing. I used the below code to create tabbar:

Tabbar.h

@interface StatusViewController : UIViewController<UITabBarControllerDelegate>

    @property (nonatomic, retain) UITabBarController *tab;

Tabbar.m

    - (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.tab setDelegate:self];

    self.tab=[[UITabBarController alloc]init];

     self.tab.view.frame = CGRectMake(0,0,320,568);

    // FirstViewController
    UploadTab *uploadview=[[UploadTab alloc]initWithNibName:nil bundle:nil];
    UINavigationController *uploadTabItem = [[UINavigationController alloc] initWithRootViewController: uploadview];
    /* uploadview.title=@"Uploading";
     uploadview.tabBarItem.image=[UIImage imageNamed:@"Uploading.png"];*/
    uploadTabItem.title=@"Uploading";
    uploadTabItem.tabBarItem.image=[UIImage imageNamed:@"Uploading.png"];

    [uploadview release];

    //Priority List ViewController
    PriorityListViewController *prioritylist=[[PriorityListViewController alloc]initWithNibName:nil bundle:nil];
    UINavigationController *priorityTabItem = [[UINavigationController alloc] initWithRootViewController: prioritylist];
    priorityTabItem.title=@"Priority list";
    priorityTabItem.tabBarItem.image=[UIImage imageNamed:@"PriorityList_Icon.png"];

    [prioritylist release];

    NSArray *viewControllersArray =[NSArray arrayWithObjects:uploadTabItem,priorityTabItem, nil];
    self.tab.viewControllers=viewControllersArray;

    [self presentViewController:self.tab animated:NO completion:nil];

}

When I'm in the Uploading tab, the loading icon is showing. I want to disable to change to other tab until the loading icon disappear. How can I do that? Thanks in advance.

Was it helpful?

Solution

plz create custom loading that call when you want loading (add that loadingview directly window ) that will display with whole screen so your tab also underneath the loading view. like this. code

-(void) showLoadingView:(NSString *)title
{
boolLodingView = YES;
UIView *viewBack = [loadView viewWithTag:999];

UILabel *lblLoading = [[UILabel alloc] initWithFrame:CGRectMake(23, 6, 110, 25)];
lblLoading.text = @"Loading...";

if (loadView == nil) {
    loadView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
    loadView.opaque = NO;
    loadView.backgroundColor = [UIColor clearColor];

    viewBack = [[UIView alloc] initWithFrame:CGRectMake(95, 230, 130, 40)];
    viewBack.backgroundColor = [UIColor blackColor];
    viewBack.alpha = 0.7f;
    viewBack.tag = 999;
    viewBack.layer.masksToBounds = NO;
    viewBack.layer.cornerRadius = 8;

    spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 10.0, 20.0, 20.0)];
    spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
    [spinningWheel startAnimating];
    [viewBack addSubview:spinningWheel];
    [spinningWheel release];

    lblLoading.backgroundColor = [UIColor clearColor];
    lblLoading.font = [UIFont fontWithName:@"Helvetica-Bold" size:16.0];

    lblLoading.textAlignment = NSTextAlignmentCenter;
    lblLoading.textColor = [UIColor whiteColor];
    lblLoading.text = @"Loading...";
    lblLoading.tag = 1111;
    [viewBack addSubview:lblLoading];
    [loadView addSubview:viewBack];
}

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    loadView.frame = iphoneFrame;
    viewBack.frame = loadiPhone;
}
else
{
    loadView.frame = ipadFrame;
    viewBack.frame = loadiPad;
}

UILabel *lbl = (UILabel *)[viewBack viewWithTag:1111];
if(lbl)
{
    lbl.text = title;
}
[self.window addSubview:loadView];
}

same as if you want hide loading view than

-(void) hideLoadingView 
{
    if(boolLodingView)
    {
      [loadView removeFromSuperview];
    }
    else
    {
      [loadViewPer removeFromSuperview];
    }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top