views:

285

answers:

1

Hi guys,

I created a viewcontroller that displays a button which is used to slide a view onto the screen. The idea is to place for instance three such viewcontrollers onscreen, resulting in three buttons at the bottom of the screen providing navigation.

The viewcontrollers get stacked, so to the top one is now overlaying the other views and therefore the other buttons. Only the top viewcontroller's button is working in this situation, where I would like all three of them to be clickable. I tried disabling userinteraction on the view and enabling it on the buttons only, but it looks like the superview settings overrule the subview settings.

Any ideas?

+1  A: 

You seem to confuse views and their controllers: viewControllers are not stacked, they are simply part of a nib or xib file. Views, on the other hand, may be part of a view hierarchy and in that sense can overlay each other. The function of a viewController is to manage and coordinate the various views on a screen. Using a view controller to manage a single button is not efficient: the purpose of a controller would be to facilitate the communication between various buttons (disabling buttons 1,2 and 4 when number 3 is touched, for instance). @bpapa's statement that using more than one viewController is discouraged by Apple is no longer correct. The present section Windows, Views, and View Controllers in the iOs Application Programming Guide states:

The view controller manages a single top-level view directly and may manage all or some of that view’s subviews. For simple user interfaces, a view controller typically manages all of the views in its view hierarchy. However, for more complex interfaces comprised of several distinct pieces, a view controller may manage a subset of views and rely on one or more custom controller objects to manage other groups of views in the view hierarchy.

One thing that is not made clear in the docs but that has bitten me several times in the past weeks is that making a viewController the target of an UIControl's action only has effect if that viewController is the File's Owner of the nib. Say, for instance, that you have a nib with two viewControllers, gameViewController and scoreViewController. The gameView might contain several buttons that act as game pieces and touching them sends an action message to gameViewController's -(void)pieceHasBeenTouched:(id)sender method. This works great if gameViewController is the File's Owner.

It now might seem logical that if you have a button in the scoreView to let it send a message to scoreViewController, say, saveScore or something like that. For reasons I'm not yet quite clear on, the Responder chain won't let you. You'll need to make the Save button in the score view send its action message to gameViewController.

I solve this problem by establishing IBOutlet bindings between the two controllers -- notifications are another possibility.

Elise van Looij
It's been a while since I asked this question! Maybe I didn't explain it properly. I am well aware of the differences between UIViews and their respective controllers. The viewcontrollers here aren't just responsible for the buttonpress action, but they are responsible for sliding an overlay in the view and managing the content (like the contentview's size color etc.). So it's basically a custom tabbarcontroller.
Syg
Sorry for casting aspersions on your abilities, but what's your point? If everything's working fine and the question wasn't that well-formulated in the first place, perhaps you should delete it and shorten the Unanswered list.
Elise van Looij