harshalb
harshalb

Reputation: 6054

How to change number of tabs in tabbar controller application?

I am developing an iPhone tabbar application with 5 tabs .

I want to show only two tabs at the launch time such as one is "locate me".

When the user taps on the locate me tab another 3 tabs will be shown and can use the current location.

I want to do some thing like "urban spoon" .

I am using the interface builder for all the stuff.

If any one have any idea , suggestion , links then provide me.

Thanks .

Upvotes: 2

Views: 2438

Answers (2)

VictorB
VictorB

Reputation: 578

// Make array which includes your existing view controllers
NSMutableArray *newVCs = [NSMutableArray arrayWithArray:[yourTabBarController viewControllers]];

// First new VC you want to add (example from a nib)
[newVCs addObject:[[[SomeCustomViewController alloc] initWithNibName:@"yourNibName" bundle:[NSBundle mainBundle]] autorelease]];

// Second new VC you want to add (example for a VC generated from code)
[newVCs addObject:[[[AnotherCustomViewController alloc] initWithNibName:nil bundle:nil] autorelease]];

// Third new VC you want to add (example from IBOutlet)
[newVCs addObject:self.yetAnotherViewController];

// Set the tab bar's view controllers to your new modified array
[yourTabBarController setViewControllers:newVCs];

Upvotes: 4

Dave DeLong
Dave DeLong

Reputation: 243156

-[UITabBarController setViewControllers:] => You can give the tab bar controller a new array of view controllers, and it will replace its existing tabs with new tabs that correspond to the view controllers in the new array.

Upvotes: 4

Related Questions