Tuesday, August 6, 2013

Navigate on clicking the tab bar item

Here I have explained that how to navigate on clicking tab bar item:-

1) In .h file add UITab bar Delegate :-


@interface StylistViewController : UIViewController<UITabBarDelegate,UITabBarControllerDelegate>
{
     
    IBOutlet UITabBar *bottomBar;
}

@property(nonatomic,retain)UITabBar *bottomBar;

2) On delegate assign delegate to self :- 



- (void)viewDidLoad
{
    [super viewDidLoad];
    
    bottomBar.delegate=self;
}


3) This is a delegate of UITab bar :-

Assign every item you add on tab bar a tag in properties -


- (void)tabBar:(UITabBar *)bottomBar didSelectItem:(UITabBarItem *)item
{
  
    NSUInteger getTagOfTabBr=item.tag;
    NSLog(@"%d",getTagOfTabBr);
    switch (getTagOfTabBr) {
        case 1:
        {
           Category *major=[[Category alloc]initWithNibName:@"Category" bundle:nil];
            [self.navigationController pushViewController:major animated:YES];

            break;
        }
        default:
            break;
    } 
}

No comments:

Post a Comment