Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the background missing on my tab bar?

The background is missing on my tab bar on iOS 7 in some cases. See screen shot:

enter image description here

I've subclassed UITabBarController and presented my subclass modally like so:

[self.navigationController presentViewController:tabBarController animated:NO completion:nil];

Sometimes, though it's rare, the background just doesn't show up on my tab bar, and I can see right through it. No translucent view - just transparency...

I've debugged using the excellent Reveal app and found that when I observe the problem, the _UITabBarBackgroundView is missing from the UITabBar at runtime (it should be a subview of UITabBar). And in case it's worth noting, the UIImageView is also missing from the UITabBar when the background is missing.

I'm at a loss. What could be causing the tab bar to be missing its _UITabBarBackgroundView subview?

like image 842
Josh Brown Avatar asked Nov 26 '13 19:11

Josh Brown


2 Answers

According to the documentation, you should never use a tab bar controller for anything other than the root view controller of your window:

When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.

It's not unreasonable to assume that presenting it modally, as you are doing, is going to have some unexpected side effects in some cases. Have you ever seen this issue when using the tab bar as the root controller of your app?

I've had "invisible" tab bars as shown in your screenshot, but only when I've tried to be clever when setting the background image, but you've said that isn't happening with your code.

like image 197
jrturton Avatar answered Oct 24 '22 17:10

jrturton


Shot in the dark: Did you override layoutSubviews without calling super?

like image 3
Jasper Blues Avatar answered Oct 24 '22 17:10

Jasper Blues