我正在编辑我的问题,我已经按照下面的方式编制了标签栏: -
FirstViewController *obj_FirstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
SecondViewController *obj_SecondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
ThirdViewController *obj_ThirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
navigation1 = [[UINavigationController alloc] initWithRootViewController:obj_FirstViewController];
navigation2 = [[UINavigationController alloc] initWithRootViewController:obj_SecondViewController];
navigation3 = [[UINavigationController alloc] initWithRootViewController:obj_ThirdViewController];
MainTabBar = [[UITabBarController alloc] init];
MainTabBar.delegate=self;
[MainTabBar setViewControllers:[NSArray arrayWithObjects:navigation1,navigation2,navigation3,nil]];
MainTabBar.view.frame=self.view.frame;
MainTabBar.selectedIndex=0;
[self.view addSubview:MainTabBar.view]
通过在(void)viewDidLoad中写这个,我在viewcontroller中得到了3个选项卡。但问题是我想将选项卡的名称设置为
我曾尝试过编写以下代码: -
但这不起作用 - 任何人都可以帮我解释如何以编程方式执行此操作吗?在哪里写行,以便在我的标签栏中获得这个3名称
答案 0 :(得分:0)
它可以在单独的视图控制器中添加tabBar,它将像rootview控制器一样,然后在根视图控制器的viewDidLoad中将tabbar的对象分配给appdelegate tabBar声明...然后单独使用appdelegate tabbar进行其他导航。 / p>
答案 1 :(得分:0)
这就是我做的方式
1)我用你的tabbar创建了一个视图控制器 2)为每个选项卡添加视图控制器,并为tabbar视图控制器类添加方法: - (void)updateContentsWithViewController:(UIViewController *)insideViewController
按下Tab键时调用该方法。
3)这里是切换的代码
- (void)updateContentsWithViewController:(UIViewController *)insideViewController {
//internalViewController is the viewController which you change
[internalViewController.view removeFromSuperview];
[internalViewController release];
internalViewController = [insideViewController retain];
navController = [[UINavigationController alloc] initWithRootViewController:insideViewController];
[navController setNavigationBarHidden:YES];
[navController.view setFrame:CGRectMake(0, 0, 320, 348)];
//frame I needed in my app .. can be changed
[self.internalView addSubview: navController.view];
//navController is the property for the navigationController
[self.view sendSubviewToBack: self.internalView];
}