user4302196
user4302196

Reputation: 93

How to add MBProgressHUD in tabbarcontroller

I had tabbarcontroller that will be called in viewcontroller1. I would like to implement MBProgressHUD(Activity Indicator) when user click on the tabbar item

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    HomeVC =[self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
    TaskVC=[self.storyboard instantiateViewControllerWithIdentifier:@"TaskNCViewController"];
    ShopVC=[self.storyboard instantiateViewControllerWithIdentifier:@"ShopNCViewController"];
    WalletVC=[self.storyboard instantiateViewControllerWithIdentifier:@"WalletNCViewController"];

    tabViewControllers = [[NSMutableArray alloc] init];
    [tabViewControllers addObject:HomeVC];
    [tabViewControllers addObject:TaskVC];
    [tabViewControllers addObject:ShopVC];
    [tabViewControllers addObject:WalletVC];

    [self setViewControllers:tabViewControllers];
    HomeVC.tabBarItem.title=@"Home";
    [HomeVC.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"home-active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"home.png"]];
    [HomeVC.tabBarItem setTitleTextAttributes:@{UITextAttributeFont:[UIFont boldSystemFontOfSize:10]} forState:UIControlStateNormal];

    TaskVC.tabBarItem.title=@"Task";
    [TaskVC.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"task-active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"task.png"]];
    [TaskVC.tabBarItem setTitleTextAttributes:@{UITextAttributeFont:[UIFont boldSystemFontOfSize:10]} forState:UIControlStateNormal];

    ShopVC.tabBarItem.title=@"Shop";
    [ShopVC.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"shop-active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"shop.png"]];
    [ShopVC.tabBarItem setTitleTextAttributes:@{UITextAttributeFont:[UIFont boldSystemFontOfSize:10]} forState:UIControlStateNormal];

    WalletVC.tabBarItem.title=@"Wallet";
    [WalletVC.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"wallet-active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"wallet.png"]];
[WalletVC.tabBarItem setTitleTextAttributes:@{UITextAttributeFont:[UIFont boldSystemFontOfSize:10]} forState:UIControlStateNormal];

    //set the status bar to white
    [self setNeedsStatusBarAppearanceUpdate];

}

Upvotes: 0

Views: 334

Answers (2)

johny kumar
johny kumar

Reputation: 1270

Create object of MBProgressHUD in

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

and implement UITabBarControllerDelegate

Upvotes: 0

Puvanarajan
Puvanarajan

Reputation: 2906

First call the delegate your header file

#import "MBProgressHUD.h"

@interface ViewController : UIViewController<MBProgressHUDDelegate>

Then your tabbar selection or where you want to show the activity

MBProgressHUD *hud= [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;

If you want to close the activity view

[hud hide:YES];

Upvotes: 1

Related Questions