这里我试图动态添加和删除uitabbarcontroller中的选项卡。如何从uitabbarcontroller中删除最后一个选项卡(如果只有三个选项卡)
以及替换它们。我的应用程序情况如下。
第一视图是登录和约
成功登录新的3个选项卡后。随着更多和另外两个。
更注销的选择是有选择这个后,我想删除的最后一个标签和
取代前两种与再次登录和版本信息。即(首页查看)
所以在我的代码即时通讯做这样........
///AppDelegate.m
(BOOL)申请:(UIApplication的* )application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//覆盖应用程序启动后自定义的点。
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]; [登录发布]; [关于发布];
[self.window addSubview:tabBarCntr.view];
[self.window makeKeyAndVisible]; }
在登录后成功树立了新viewcontrollers我IBAction为以tabbarcontroller
self.tabBarController.viewControllers = [NSArray的
arrayWithObjects:newController1,newController2,更多,零];
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提前。
Paggyyyyy
编辑:NSMutableArray的arrayWithArray增值空间来修复代码
thnks很多,但我怎样才能使用两个单独的tabbarcontroller,因为我添加第一个作为subview到窗口 – user968597 2012-01-10 11:40:25
使appDelegate中的标签栏控制器的2个实例,在这里你可以写一种在窗口上添加的方法。您可以在此方法中维护标签栏。 – vishy 2012-01-10 11:43:13
@vishy非常感谢你的建议对我也有帮助。我仍然很惊讶,为什么我没有想到这个简单的解决方案。 – pankaj 2013-03-12 09:15:03