Friday 18 May 2012

how to make TabBar in iphone sdk

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
   
    imgBackground.image =[UIImage imageNamed:@"splash.png"];
   
    appDel = (AppDelegate*)[[UIApplication sharedApplication] delegate];
   
    tab=[[UITabBar alloc]initWithFrame:CGRectMake(0.0, 412,self.view.bounds.size.width, 49.0)];
    tab.delegate=self;
   
    [self.view addSubview:tab];
    [self createTabBarItems];
   

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)createTabBarItems{   
   
      tbEvent =[[UITabBarItem alloc] initWithTitle:@"Event" image:[UIImage imageNamed:@"latest.png"] tag:0];
   
    tbAbout = [[UITabBarItem alloc] initWithTitle:@"AboutUs" image:[UIImage imageNamed:@"about.png"] tag:1];
   
    tbContact = [[UITabBarItem alloc] initWithTitle:@"ContactUs" image:[UIImage imageNamed:@"contact.png"] tag:2];
   
    tab.items =[[NSArray arrayWithObjects:tbEvent,tbAbout,tbContact,nil] retain];
   
    [self.view addSubview:tab];
   
    [tab release];
   
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
   
    //    if(tabBar.selectedItem.tag == 0)
    //    {
    //        self.tab.selectedItem = tbHome;
    //   
    //    }
    if(tabBar.selectedItem.tag == 0)
    {
       // appDel.activityView.hidden = NO;
        EventViewController *eventView = [[EventViewController alloc] initWithNibName:@"EventViewController" bundle:nil];
        [self.navigationController pushViewController:eventView animated:NO];
        [eventView release];
    }
    if (tabBar.selectedItem.tag == 1) {
       
        AboutUsViewController *aboutView = [[AboutUsViewController alloc] initWithNibName:@"AboutUsViewController" bundle:nil];
        [self.navigationController pushViewController:aboutView animated:NO];
        [aboutView release];
    }
    if (tabBar.selectedItem.tag == 2) {
        ContactUsViewController *contactView = [[ContactUsViewController alloc] initWithNibName:@"ContactUsViewController" bundle:nil];
        [self.navigationController pushViewController:contactView animated:NO];
        [contactView release];
    }
   
}

No comments:

Post a Comment