当我创建四个导航控制器并将它们添加到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)有一个奇怪的'pop'动画。导航栏中的标题等正确动画,但导航控制器的内容在没有动画的情况下更改。
选择其他选项卡,然后返回原始选项卡可以解决问题。
此外,如果我将self.window.rootViewController
设置为[[[UINavigationController alloc] initWithRootViewController:secondViewController] autorelease]
以便将标签栏排除在等式之外,导航控制器也能正常工作。
有什么想法吗?
答案 0 :(得分: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;
答案 1 :(得分:1)
我遇到了同样的问题并找到了解决方案,所以对于那些在谷歌搜索时偶然发现此页面的人:
来自Pop animation is not working in first UINavigationController of UITabbarController:
您可能忘记在[super viewDidAppear:animated];
方法中写-(void)viewDidAppear:(BOOL)animated
:
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
}
这应该解决它。
答案 2 :(得分: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];