Take the 2-minute tour ×

I have two UIViewControllers which I sometimes need to show at the same time. Imagine ViewController A only has one button and is otherwise transparent. Once I touch the button I would like ViewController B (which is green) to fade in and do other custom animations, but ViewController A (and the button) needs to be still shown on top of B. Once the fade/animation etc. are over, only ViewController B (green) is visible.

My questions:

1) What is the best setup? UINavigationController with hidden NavBar doesn't make much sense. TabBarController with hidden TabBar strikes me as equally odd as I don't need the TabBar. 2) I'm a bit confused about views and windows. The window is init'ed in my AppDelegate and then I would add a RootViewController:

self.viewController = [[ViewController alloc] init];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

If I want to have two ViewController's views on top of each other as described above, would I need to add the view of ViewController B (the green one) to ViewController A (the one with the button)? Do I need to swap the rootViewControllers?

Ideally, I don't want to take care of all the ViewDidAppear's of VC A and B, so I guess UINavigationController/TabBar would not be a bad idea after all, if I could customise the transitions between Controllers.


I really need two different VCs as I would do more complex things than just display a button, like having a scrollview in VC A and another scrollview in VC B. I don't want to have two scrollviews (or tableViews etc.) in one VC as this gets messy.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The best way is to have only one view controller. View A will just sit on top of B until you fade it out.

share|improve this answer
Yes, but I'd like to have more features in both ViewControllers than indicated above, like having a scrollview in one and another scrollview in the other. I could do this with just one ViewController, but it would get really messy as I would need to ask which scrollview is currently moved etc.. So ideally, I'd like to have another VC. –  n.evermind Mar 13 '12 at 12:03
A scrolllview is just a UIView. There is no advantage to having it contained in a separate view controller. If you are worried about code getting messy than make view a and view b custom view classes that contain other views. –  sosborn Mar 13 '12 at 13:35
But as far as I understand it, a scrollview always needs a delegate which is a ViewController, not? Where would be my delegate methods be (like scrollViewDidScroll) if I had a scrollView in View A and another scrollView in View B? Could View A and B be the delegates? –  n.evermind Mar 13 '12 at 15:04
You can assign any object to be a delegate, you just have to make sure it complies with the required delegate methods. I usually make a simple NSObject subclass that implements the delegate methods for cases where I want to keep the delegate code separated. It sounds like you are just getting started with iOS development. It would be good to read through Apple's iOS Core Competency series of guides on the developer website. –  sosborn Mar 14 '12 at 0:12

Your Answer


