iOS 10 UITabBar设置标题后可以看到更多项目

Cra*_*ake 11 ios ios10

我的应用程序中有一个标签栏,标签栏项是UITabBarItem的子类.从服务器获取更新后,这些选项卡栏项使用以下行从代码中设置其标题:

[self setTitle:@"SomeText"];
Run Code Online (Sandbox Code Playgroud)

运行此行后,先前隐藏的选项卡栏项(在更多选项卡后面)将在主选项卡区域中显示,并堆叠在其他选项卡的顶部.请参见下面的截图.这只发生在iOS 10(测试版)中.这是我的代码中的错误还是iOS 10中的问题?

我创建了一个最小的XCode项目并发布到Github来演示这个问题:https: //github.com/RippleAdder/TabStacks

在此输入图像描述

Cra*_*ake 6

当您在iOS 10中以编程方式设置选项卡的标题时,就会发生这种情况.我已经确认这是iOS 10测试版中的错误.我已经打开了一个错误报告和雷达:openradar.appspot.com/27749026

我还发布了一个演示该问题的Github回购:https://github.com/RippleAdder/TabStacks


sha*_*ady 6

这个答案不会解决您的具体情况,但可以帮助其他人解决同样的问题.

如果您使用UIViewControllers tabBarItem属性来设置标题,则似乎会出现此问题.而是使用UITabBarController tabBar属性来解决问题.

所以而不是(例如):

tabBarController.viewControllers[0].tabBarItem.title = @"SomeText";
Run Code Online (Sandbox Code Playgroud)

使用:

tabBarController.tabBar.items[0].title = @"SomeText";
Run Code Online (Sandbox Code Playgroud)

更新

我们发现替换UITabBarItem是此iOS 10错误的另一种解决方法:

UITabBarItem *item = tabBarController.viewControllers[0].tabBarItem;
tabBarController.viewControllers[0].tabBarItem = [[UITabBarItem alloc] initWithTitle:@"SomeText" image:item.image tag:item.tag];
Run Code Online (Sandbox Code Playgroud)