我在第4屏幕上添加了标签控制器。最多4个屏幕,我的导航栏可见 现在在第4个屏幕上,当我将Tab Controller添加到窗口时,导航栏正在消失......
code written in the tabbedController class is :
- (void)viewDidLoad
{
self.tabController = [[UITabBarController alloc]init];
FirstTabScreen *firstTab = [[FirstTabScreen alloc]initWithNibName:nil bundle:nil];
SecondTabScreen *secondTab = [[SecondTabScreen alloc]initWithNibName:nil bundle:nil];
firstTab.title=@"First";
firstTab.tabBarItem.image = [UIImage imageNamed:@"small_star.png"];
secondTab.title=@"second";
secondTab.tabBarItem.image = [UIImage imageNamed:@"small_star.png"];
tabController.viewControllers = [NSArray arrayWithObjects:
firstTab,
secondTab,
nil];
// self.tabWindow = [[[[UIApplication sharedApplication]keyWindow ]subviews ] lastObject];
//self.tabWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// self.tabWindow = [[UIApplication sharedApplication] keyWindow ];
//self.tabWindow = self.appDelegateAccess.window;
self.tabWindow = self.appDelegateAccess.window;
[self.tabWindow addSubview:tabController.view];
[self.tabWindow makeKeyAndVisible];
// [self.view addSubview:tabsContainer.view];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
请让我知道我哪里出错了.... 我想我没有引用添加选项卡控制器的根窗口。 它是这种情况,请建议我采取根窗口添加标签控制器的方法
由于
答案 0 :(得分:1)
为什么要在窗口中添加tabbarcontroller。为什么不在self.view中添加它?
答案 1 :(得分:0)
首先在YourAppDelegate中创建tabBar的对象。并在以下methode中编写以下代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabController = [[UITabBarController alloc]init];
FirstTabScreen *firstTab = [[FirstTabScreen alloc]initWithNibName:nil bundle:nil];
SecondTabScreen *secondTab = [[SecondTabScreen alloc]initWithNibName:nil bundle:nil];
firstTab.title=@"First";
firstTab.tabBarItem.image = [UIImage imageNamed:@"small_star.png"];
secondTab.title=@"second";
secondTab.tabBarItem.image = [UIImage imageNamed:@"small_star.png"];
tabController.viewControllers = [NSArray arrayWithObjects:
firstTab,
secondTab,
nil];
/*
Your Other Code
*/
}
然后在您的第三个View控制器的.m文件中导入您的appDelegate,如..
#import "YourAppDelegate.h"
上一步在选择第三个视图控制器的行时编写以下代码...
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
YourAppDelegate * appDel = (YourAppDelegate *)[[UIApplication SharedApplication] delegate];
[appDel.window setRootViewController:appDel.tabController];
}
答案 2 :(得分:0)
您需要单独添加导航控制器,
试试这个,
self.tabController = [[UITabBarController alloc]init];
FirstTabScreen *firstTab = [[FirstTabScreen alloc]initWithNibName:nil bundle:nil];
SecondTabScreen *secondTab = [[SecondTabScreen alloc]initWithNibName:nil bundle:nil];
UINavigationController *navControllerOne = [[UINavigationController alloc] initWithRootViewController: firstTab];
navControllerOne.navigationBar.tintColor = [UIColor blackColor];
navControllerOne.tabBarItem.image=[UIImage imageNamed:@"star.png"];
navControllerOne.tabBarItem.title = @"First";
UINavigationController *navControllerTwo = [[UINavigationController alloc] initWithRootViewController: secondTab];
navControllerTwo.navigationBar.tintColor = [UIColor blackColor];
navControllerTwo.tabBarItem.image=[UIImage imageNamed:@"star.png"];
navControllerTwo.tabBarItem.title = @"Second";
tabController.viewControllers = [NSArray arrayWithObjects:
navControllerOne,
navControllerTwo,
nil];
// self.tabWindow = [[[[UIApplication sharedApplication]keyWindow ]subviews ] lastObject];
//self.tabWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// self.tabWindow = [[UIApplication sharedApplication] keyWindow ];
//self.tabWindow = self.appDelegateAccess.window;
self.tabWindow = self.appDelegateAccess.window;
[self.tabWindow addSubview:tabController.view];
[self.tabWindow makeKeyAndVisible];
// [self.view addSubview:tabsContainer.view];
答案 3 :(得分:0)
我已删除
self.tabWindow = self.appDelegateAccess.window;
[self.tabWindow addSubview:tabController.view];
[self.tabWindow makeKeyAndVisible];
并且只添加了一行
[self.view addSubview:tabController.view];
最后它有效!!!
感谢Rohit ..