Friday, 6 July 2012

Creating Tabs on a view controller. and its Delegate

- (void)viewDidLoad {
    [super viewDidLoad];

UITabBar *m_tabbar;
if(m_tabbar)
        [m_tabbar removeFromSuperview];
   
    m_tabbar =  [[UITabBar alloc] initWithFrame:CGRectMake(0,422,320,40)];
    m_tabbar.backgroundColor = [UIColor redColor];
    [m_tabbar setDelegate:self];
    UITabBarItem* setttings = [[[UITabBarItem alloc] initWithTitle:@"Most Recent" image:[UIImage imageNamed:@"Settings.png"] tag:1]autorelease];
    UITabBarItem* mapbutton = [[[UITabBarItem alloc] initWithTitle:@"Community" image:[UIImage imageNamed:@"map.png"] tag:2]autorelease];
    UITabBarItem* nilbutton = [[[UITabBarItem alloc] initWithTitle:@"Settings" image:[UIImage imageNamed:@"locate.png"] tag:3]autorelease];
    NSArray* tabBarItems = [NSArray arrayWithObjects:setttings, nilbutton,mapbutton, nil];
    m_tabbar.items = tabBarItems;

self.view addSubview:m_tabbar];
    [m_tabbar setSelectedItem:[m_tabbar.items objectAtIndex:0]];

}


- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    switch (item.tag)
    {
        case 1:{
            Settings * setii=[[Settings alloc]init];
           [self.navigationController pushViewController:setii animated:YES];
            break;
        }
        case 2:
                    
            break;
           
           
        case 3:
        {
                       break;
        }   
        default:
            exit(0);
            break;
    }
}

No comments:

Post a Comment