Ios7 在“更多”选项卡上时,iOS 7选项卡栏图标暂时消失
当我将导航控制器嵌入的视图控制器添加到选项卡栏时,当返回到“更多”选项卡时,其图标+标题会短暂消失 但是,当添加视图控制器时,图标+图像正常,不会消失 我已经尝试了很多东西,但我没有选择。有什么想法吗 这是我的Ios7 在“更多”选项卡上时,iOS 7选项卡栏图标暂时消失,ios7,uinavigationcontroller,uitabbar,uitabbaritem,Ios7,Uinavigationcontroller,Uitabbar,Uitabbaritem,当我将导航控制器嵌入的视图控制器添加到选项卡栏时,当返回到“更多”选项卡时,其图标+标题会短暂消失 但是,当添加视图控制器时,图标+图像正常,不会消失 我已经尝试了很多东西,但我没有选择。有什么想法吗 这是我的AppDelegate代码: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [
AppDelegate
代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[UITabBarController alloc] init];
// Must be placed here, just before tabs are added. Otherwise navigation bar
// will overlap with status bar.
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
[self addViewControllersToTabBar];
self.window.rootViewController = self.tabBarController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)addViewControllersToTabBar
{
NSArray* tabBarClassNames =
@[
NSStringFromClass([FirstViewController class]),
NSStringFromClass([SecondViewController class]),
NSStringFromClass([FirstViewController class]),
NSStringFromClass([FirstViewController class]),
NSStringFromClass([FirstViewController class]),
NSStringFromClass([SecondViewController class]),
NSStringFromClass([FirstViewController class]),
];
NSMutableArray* viewControllers = [NSMutableArray array];
for (NSString* className in tabBarClassNames)
{
UIViewController* viewController = [[NSClassFromString(className) alloc] init];
UINavigationController* navigationController;
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewControllers addObject:navigationController];
}
[viewControllers addObject:[[FirstViewController alloc] init]]; // This one is fine.
self.tabBarController.viewControllers = viewControllers;
self.tabBarController.selectedViewController = viewControllers[2];
}
视图控制器实际上只不过是:
@implementation SecondViewController
- (instancetype)init
{
if (self = [super init])
{
self.title = @"second";
self.tabBarItem.image = [UIImage imageNamed:@"second.png"];
}
return self;
}
@end
天哪,我花了这么多时间在这个bug上,但这是我的解决方法。而不是:
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
我创建了自己的NavigationController
作为UINavigationController
的子类:
@implementation NavigationController
- (instancetype)initWithRootViewController:(UIViewController*)rootViewController
{
if (self = [super initWithRootViewController:rootViewController])
{
NSString* className = NSStringFromClass([rootViewController class]);
NSString* name = [className stringByReplacingOccurrencesOfString:@"ViewController" withString:@""];
self.tabBarItem.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@Tab.png", name]];
}
return self;
}
@end
然后做:
navigationController = [[NavigationController alloc] initWithRootViewController:viewController];
先决条件是选项卡图像的基本名称与视图控制器类名相同,这在我的应用程序中已经存在
我在视图控制器的
init
方法中设置了self.tabBarItem.image
,这似乎造成了我看到的效果。因此,除了使用我自己的导航控制器外,我还简单地删除了在每个单独的视图控制器中设置tabBarItem
。我遇到了同样的问题。但是,我发现我可以在初始化UINavigationController之后设置tabBarItem,而不是子类化。这可能只是我的特殊情况,但如果其他人收到这个问题,他们也有另一个选择来尝试。@kailoon在iOS 7上也是这样吗,就像我的问题一样?