Search code examples
iosiphoneswiftuitabbaruitabbaritem

UITabBarIcon invisible until the next time tick


I have got a strange problem that may be some of you will be able to explain and thus allow me to fix it.

Let me explain what is going on, I have a simple application displaying a UITabBar at the bottom with 5 items. All are set using the interface builder in my main storyboard file.

It worked very well until I added another view before the one containing my tabs (before, the view was my storyboard's entrypoint, after, I have a splash screen).

The problem occuring is really strange, my tab bar icons are invisible until :

  • I click an item,toggling the active state allows its icon to appear
  • I wait the next minute tick (app is launched at 09h32 10s, icon will appear without me doing anything at 09h33 00s)

I scratched my head and didn't find a way to 'force' the UITabBar to draw its subviews (hoping that it will redraw the icons).

If I set the entrypoint of my storyboard back to my view hosting the tab bar, the problem disappear.

For the record the app is targeting iOS 9.1 but the bug occurs also under 8.4, on simulator and real devices. It is developped using Swift 2 and no external library. Here is what the bug looks like


Solution

  • This is Quick fix:

    When you present tabbar from splash screen just do following for all tab items

    self.tabBarItem().setSelectedImage(UIImage(Named:"selected image file")