views:

12

answers:

1

Hi friends,

I have created tab bar programmatically in the view controller. In my application, Initially displayed the tabbar and it has five tab bar items in the view.Using tab bar, Initially first tab item is selected. Now i want to change the selected items like, fourth item is initially selected.(See the image)
How do i achieve this?

Here my code is,

    tBar = [[UITabBarController alloc] init];

    first = [[first alloc] initWithNibName:@"first" bundle:nil];

    UINavigationController *navFirst = [[[UINavigationController alloc] initWithRootViewController:first] autorelease];

    second = [[second alloc] initWithNibName:@"second" bundle:nil];

    UINavigationController *navsecond = [[[UINavigationController alloc] initWithRootViewController:second] autorelease];

    third = [[third alloc] initWithNibName:@"third" bundle:nil];

   UINavigationController *navthird = [[[UINavigationController alloc] initWithRootViewController:third] autorelease];

   fourth = [[fourth alloc] initWithNibName:@"fourth" bundle:nil];

    UINavigationController *navfourth = [[[UINavigationController alloc] initWithRootViewController:fourth] autorelease];

   fifth = [[fifth alloc] initWithNibName:@"fifth" bundle:nil];

   UINavigationController *navfifth= [[[UINavigationController alloc] initWithRootViewController:fifth] autorelease];

   tBar.viewControllers = [NSArray arrayWithObjects:navFirst,navsecond, navthird, navfourth, navfifth,nil]; 

   [self.view addSubview:tBar.view];

   [self.navigationController pushViewController:tBar animated:NO];

See the below image. I want exactly like this,

image

Please guide me.

Thanks.

A: 

Try this:

YourAppNameDelegate *appDelegate = (YourAppNameDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabBarController].selectedIndex = 3;

or

tBar.selectedIndex = 3;
domino
Thanks for the quick reply.
Pugal Devan