iphone - MoreNavigationController 图像在选择时消失

标签 iphone uitabbarcontroller

我有一个以编程方式创建的 UITabBarController,它有 6 个选项卡。因此,会自动创建 MoreNavigationController 来处理超过 5 个选项卡。当显示 MoreNavigationController 时,一切看起来都很好,但是当我选择其中一行将 View Controller 推送到堆栈时,单元格图像(选项卡栏图像)消失。当我弹出该 View Controller 时,图像保持隐藏状态,直到弹出动画完成,此时图像突然再次出现。

这是相当旧的代码,现在我不会这样做,但除了最后一件小事之外,一切都有效,所以我很犹豫是否要撕掉所有代码并以另一种方式做。谁能建议我可能做错了什么?

创建标签栏 View Controller 之一的示例:

InfoViewController* infoViewController = [[InfoViewController alloc] init];
infoViewController.tabBarItem.image = [UIImage imageNamed:@"90-life-buoy.png"];
infoViewController.tabBarItem.title = @"More Info";
infoViewController.title = @"More Info";
UINavigationController* infoNavController = [[UINavigationController alloc] initWithRootViewController:infoViewController];
[infoViewController release];

创建标签栏:

tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:outdoorsNavController, peopleNavController, citiesNavController, landscapesNavController, infoNavController, basicsNavController, nil];
[window addSubview:tabBarController.view];

编辑:无论我是否使用视网膜(@2x)图像似乎都没有任何区别。

最佳答案

问题是因为您将 InfoViewController 包装在 UINavigationController 中。

当您单击 MoreNavigationController 中的表格行时, Controller 在进行转换时会使用 UINavigationController 中的 tabBarItem。因为这是 nil(在您的代码中),所以 MoreNavigationController 中的图像消失了。当转换最终完成时,MoreNavigationController 会选取 InfoViewController

中的 tabBarItem

试试这个:

InfoViewController* infoViewController = [[InfoViewController alloc] init];
infoViewController.tabBarItem.image = [UIImage imageNamed:@"90-life-buoy.png"];
infoViewController.tabBarItem.title = @"More Info";
infoViewController.title = @"More Info";
UINavigationController* infoNavController = [[UINavigationController alloc] initWithRootViewController:infoViewController];
//Set the tabBarItem for UINavigationController
infoNavController.tabBarItem = infoViewController.tabBarItem
[infoViewController release];

这是重现和解决该问题的视频: 项目 7 有一个空的 tabBarItem.image,而项目 6 有 tabBarItem.image 设置

关于iphone - MoreNavigationController 图像在选择时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3748342/

相关文章:

iphone - 在我的对象类中使用 typedef 枚举

iphone - 如何在具有视网膜显示图形的 iPad 上显示 iPhone 应用程序?

swift - 单击通知时更改选项卡栏

ios - 以模态方式呈现 ViewController 时如何禁用所有 UITabBarItems?

ios - UITabBarController 在 Swift 语言中设置默认选项卡

ios - Phonegap + iphone 6 屏幕尺寸问题

iphone - Bundle ID 应该如何用于多个 Apple 应用程序?

iphone - 更新 block 中的 NSUInteger 属性。警告 : Block will be retained by

ios - 两个 UITabBarControllers 共享一个 ViewController(作为选项卡内容)?

ios - UITabBar 按钮中心垂直对齐 Swift