2

当我创建四个导航控制器并将它们添加到 UITabBar 时,如下所示:

// Create the root view controllers for the tab bar
firstViewController = [[FirstViewController alloc] init];
secondViewController = [[SecondViewController alloc] init];
thirdViewController = [[ThirdViewController alloc] init];
fourthViewController = [[FourthViewController alloc] init];

// Configure the tab bar
UITabBarController *tabBarController = [[[UITabBarController alloc] init] autorelease];
tabBarController.viewControllers = @[
[[[UINavigationController alloc] initWithRootViewController:firstViewController] autorelease],
[[[UINavigationController alloc] initWithRootViewController:secondViewController] autorelease],
[[[UINavigationController alloc] initWithRootViewController:thirdViewController] autorelease],
[[[UINavigationController alloc] initWithRootViewController:fourthViewController] autorelease]
];
tabBarController.selectedIndex = 1;

self.window.rootViewController = tabBarController;

我遇到了一个问题,即哪个 UINavigationController 在启动时首次可见(在本例中为索引 1)有一个奇怪的“弹出”动画。导航栏中的标题等动画正确,但导航控制器的内容没有动画变化。

选择不同的选项卡,然后返回到原始选项卡可以解决问题。

此外,如果我设置self.window.rootViewController[[[UINavigationController alloc] initWithRootViewController:secondViewController] autorelease]使选项卡栏不在等式中,导航控制器就可以正常工作。

有什么想法吗?

4

3 回答 3

1

我遇到了同样的问题,我发现的唯一解决方案是这个小技巧:

将它放在第一个 UITabBarController 视图控制器上的“(void)viewWillAppear”方法中。

     UITabBarController * controller = self.tabBarController;
     //Create this BOOL variable on your class and set it to YES on viewDidLoad
     if(firstTimeViewLoaded) {    
        // Simulate a click on other tab item then switch back instantly.
        [controller setSelectedViewController:controller.viewControllers[1]];
        [controller setSelectedViewController:controller.viewControllers[0]];
     }
     firstTimeViewLoaded = NO;
于 2014-09-24T12:39:50.673 回答
1

我遇到了同样的问题并找到了解决方案,所以对于那些在谷歌搜索时偶然发现此页面的人:

Pop 动画在 UITabbarController 的第一个 UINavigationController 中不起作用

您可能忘记[super viewDidAppear:animated];在方法内部编写-(void)viewDidAppear:(BOOL)animated

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}

这应该解决它。

于 2016-03-16T13:58:01.787 回答
0
 // Create the root view controllers for the tab bar
firstViewController = [[FirstViewController alloc] init];
secondViewController = [[SecondViewController alloc] init];
thirdViewController = [[ThirdViewController alloc] init];
fourthViewController = [[FourthViewController alloc] init];

   UINavigationController *myNavigationController;
    UITabBarController *myTabBarController = [[UITabBarController alloc] init];

    NSMutableArray *myTabs = [[NSMutableArray alloc] init];

    myNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
    [myTabs addObject:myNavigationController];
//Release
[myNavigationController release];
//Second view
    myNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
    [myTabs addObject:myNavigationController];
[myNavigationController release];
//And so on with the third and fourth view controller
//...

[tabBarController setViewControllers:myTabs];
//Add the tab bar controller view to the main view
[self.window addSubview:tabBarController.view];
于 2013-01-09T17:32:07.150 回答