0

我有以下带有 uiTabBarItems 的 TabBarController

[项目1,项目2,项目3,项目4]

这个结构工作正常(每个 ViewController 都正确显示),我的问题是:

当我从 Item1、Item2 更改为另一个 ViewController ... TabBarItems 底部被隐藏/丢失

[, , , ]

我正在使用以下代码从 Item1 ViewController 更改 viewController

NewViewController *controller = [[NewViewController alloc]init];
[self.tabBarController setViewControllers:[[NSArray alloc] initWithObjects:controller, nil]];

使用前面显示的代码正确更改视图控制器吗?

编辑。-

基本上我想在 Item1 (UITabBar) 的 ViewControllers 上导航而不会丢失 UITabBarItems

4

2 回答 2

0

尝试这个。

调用这个方法,在哪里展示UITabBar

在.h中,

@property (strong, nonatomic) UINavigationController *navigation;
@property(nonatomic, strong) UITabBarController *tabbarcontroller;

米,

-(void)loadtabview
{

    self.tabbarcontroller = [[UITabBarController alloc] init];
    NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:4];
    self.firstViewController = [[FirstViewController alloc]initWithNibName:@"firstViewController" bundle:nil];
    navigation = [[UINavigationController alloc] initWithRootViewController:self.firstViewController];
    self.viewController.navigationItem.title=@"First";
    [localControllersArray addObject:navigation];


    self.secondViewController = [[secondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];
    navigation = [[UINavigationController alloc] initWithRootViewController:secondViewController];
    self.secondViewController.navigationItem.title=@"second";
    [localControllersArray addObject:navigation];


    self.ThirdViewController = [[Third ViewController alloc]initWithNibName:@"Third ViewController" bundle:nil];
    navigation = [[UINavigationController alloc] initWithRootViewController:ThirdViewController];
    self.secondViewController.navigationItem.title=@"Third";
    [localControllersArray addObject:navigation];

    tabbarcontroller.viewControllers = localControllersArray;
    self.tabbarcontroller.delegate = self;
    [self.tabbarcontroller setSelectedIndex:0];
    [self.window addSubview:tabbarcontroller.view];

}
于 2013-03-04T06:36:12.470 回答
0

如果要设置活动选项卡,则不应使用setViewControllers:,因为它会替换所有选项卡。你应该使用setSelectedIndex:你的UITabBarController代替。

于 2013-03-04T00:19:20.027 回答