0

我在第四个屏幕上添加标签控制器。直到第 4 个屏幕,当我将选项卡控制器添加到窗口时,我的导航栏现在在第 4 个屏幕上可见,导航栏正在消失......

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.
}

请让我知道我哪里出错了....我想我没有引用根窗口来添加选项卡控制器..是这种情况请建议我使用根窗口添加选项卡控制器的方法

这是第三屏...

这是第四屏

谢谢

4

4 回答 4

1

为什么要在窗口中添加 tabbarcontroller。为什么不将它添加到 self.view 中?

于 2013-10-25T11:12:57.793 回答
0

You need to add navigation controller separately,

Try this,

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];
于 2013-10-25T11:05:56.463 回答
0

伟大的 !!!!它修复了...

我已删除

 self.tabWindow = self.appDelegateAccess.window;
    [self.tabWindow addSubview:tabController.view];
    [self.tabWindow makeKeyAndVisible];

并且只添加了一行

[self.view addSubview:tabController.view];

终于成功了!!!

谢谢罗希特..

于 2013-10-25T11:24:23.590 回答
0

首先在 YourAppDelegate 中创建 tabBar 的对象。并在以下方法中编写以下代码

- (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
    */
}

然后在你的第三个视图控制器的 .m 文件中导入你的 appDelegate 像..

#import "YourAppDelegate.h"

最后一步在选择第三个视图控制器的一行时编写以下代码...

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     YourAppDelegate * appDel = (YourAppDelegate *)[[UIApplication SharedApplication] delegate];
     [appDel.window setRootViewController:appDel.tabController];

}
于 2013-10-25T11:01:39.480 回答