views:

33

answers:

1

Hello,

I have an existing iPhone View Controller with a corresponding view (via nib) that displays an interactive graph. The user can touch a cursor point to move along the curve and get data corresponding to the touch point.

Now, I'd like to create a new screen that is a kind of "compare" screen the combines two of these existing views. So, a user can see two graphs of different curves and interact with each separately. I think it would be fine if the exact existing views were used, just resized to fit in half the space.

Any opinions on what's the best way to approach this while maximizing reuse?

A: 

Apple's documentation recommends using only one view controller per screen on the iPhone. The framework wasn't really designed to support multiple view controllers per screen, but you can get away with it if you're careful.

I recommend creating a CompositeViewController class that contains references to the two child view controllers. The view of the CompositeViewController is set to a full-screen wrapper view. The view of each child view controller is set to the appropriate subview.

The key to making this work is to manually delegate certain calls from the CompositeViewController down to the child view controllers. In particular, you'll need to delegate these methods if you want them to get called on your child view controllers:

  • viewWillAppear:animated:
  • viewDidAppear:animated:
  • viewWillDisappear:animated:
  • viewDidDisappear:animated:
cduhn