1

I stuck in a strange problem.

My app is not a UITabBarController application, while I added a UITabBar to self.window.

On appDelegate's didFinishLaunchingWithOptions I added UITabBar like this:

UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
     window = [[UIApplication sharedApplication].windows objectAtIndex:0];
    [[[window subviews] objectAtIndex:0] addSubview:self.tabbar];

Adding directly as subView of window, UITabBar does not rotate with device, so I added it as above code.

When app launches, it shows a conditional UIAlertView like this screenshot and UITabBar also looks good here:

enter image description here

But when I click YES or NO, then UITabBar also goes hidden as UIAlertView enter image description here

Why it happens? I tried adding UITabBar on UIAlertView click but same issue. Issue does not come if UITabBar is added directly to window as [self.window addsubview:self.tabbar]; Any help?

(It has several reasons why it is not a UITabBarController app. I found adding UITabBar more useful as per my app's requirements.)

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
  • 2
    You're doing nasty, hacky things you're not supposed to do (`[[[window subviews] objectAtIndex:0] addSubview:self.tabbar];`) and that's the price you're paying ;-) You need to find a different, clean way to add your tab bar to your view hierarchy. Also, `window = [[UIApplication sharedApplication].windows objectAtIndex:0];` might give you something that's not your app's main window. – DarkDust Jun 17 '14 at 12:15
  • Then whats other option if I want to allow rotation of `UITabBar` along with `device`? – Vaibhav Saran Jun 17 '14 at 12:17
  • Correctly implement a root view controller that allows for rotation. Maybe you should try to use a `UITabBarController` after all: don't try fight the system, try to understand it. – DarkDust Jun 17 '14 at 12:21
  • But if you'd like to continue your hacky way: you could experiment with something like this: subclass `UITabBar`, override `didMoveToWindow` and when `[self window]` is nil, re-add it to your window :-) Maybe you'll need to do it in the next runloop iteration, e.g. using `performSelector:withObject:afterDelay:` and a delay of 0 or `dispatch_after`. – DarkDust Jun 17 '14 at 12:27
  • The problem might be that you are adding the TabBar to the UIAlertView and not your window. The thing is, that when a UIAlertView is shown it will become the keyWindow! So if you are already showing the alertView and add a subview to the keyWindow, you are adding subviews to the alertView. – justMartin Jul 10 '14 at 15:57

0 Answers0