Here i am trying to dynamically add and remove the tab from uitabbarcontroller .
As well as replace them . My apps situation is as below.
First view is Logon and about
After successful logon new 3 tabs . With last as More and two other .
In more Logoff option is there after selecting this i want to remove the last tab and
replace first two with again logon and About. i.e (Home View)
So in my code i m doing like this ……..
///AppDelegate.m
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window.rootViewController = tabBarCntr;
tabBarCntr=[[UITabBarController alloc]init];
LogonViewController *logon=[[LogonViewController alloc]init];
logon.tabBarItem.title=@”Logon”;
AboutViewController *about=[[AboutViewController alloc]init];
about.tabBarItem.title=@”About”;
tabBarCntr.viewControllers=[NSArray arrayWithObjects:sos1,about,nil];
[logon release];
[about release];[self.window addSubview:tabBarCntr.view];
[self.window makeKeyAndVisible];
}
and in my IBAction after logon successful setting new viewcontrollers to tabbarcontroller
self.tabBarController.viewControllers=[NSArray
arrayWithObjects:newController1,newController2,more,nil];
Now in my loggoff i coding something like.....
NSMutableArray *newArray;
newArray=[NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
[newArray replaceObjectAtIndex:0 withObject:logon];
[newArray replaceObjectAtIndex:1 withObject:about];
[newArray removeLastObject];
self.tabBarController.selectedIndex=0;
[self.tabBarController setViewControllers : newArray];
but my applcation crash here after this ....
can any has solution for this ...
Thnx in advance.
Paggyyyyy
Edit: NSMutableArray arrayWithArray added space to fix code
In my opinion, you use 2 separate tabBarControllers. one for login and other for app. once you login remove & release the login tab and add app tab. And again after logout remove & release app tab and add the login tab.
This will be easier to access tabs, instead of removing/adding viewcontrollers, renaming tabs, changing tab images.