【发布时间】:2012-02-06 18:21:36
【问题描述】:
我在这里尝试从 uitabbarcontroller 动态添加和删除选项卡。
以及替换它们。我的应用情况如下。
第一个视图是登录和关于
成功登录后新的 3 个选项卡。最后一个是 More 和另外两个。
选择此选项后,我想删除最后一个选项卡和
将前两个替换为再次登录和关于。即(主视图)
所以在我的代码中我正在这样做............
///AppDelegate.m
-
(BOOL)应用程序:(UIApplication *)应用程序 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 应用程序启动后的自定义覆盖点。
self.window.rootViewController = tabBarCntr; tabBarCntr=[[UITabBarController alloc]init]; LogonViewController *logon=[[LogonViewController alloc]init]; logon.tabBarItem.title=@"登录"; AboutViewController *about=[[AboutViewController alloc]init]; about.tabBarItem.title=@"关于"; tabBarCntr.viewControllers=[NSArray arrayWithObjects:sos1,about,nil]; [登录发布]; [关于发布];
[self.window addSubview:tabBarCntr.view];
[self.window makeKeyAndVisible]; }
在我的 IBAction 中成功登录后将新的视图控制器设置为 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 ...
提前谢谢。
帕吉耶
编辑:NSMutableArray arrayWithArray 添加了空间来修复代码
【问题讨论】: