开发者

Best way to combine existing views/controllers?

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 n开发者_高级运维ew 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?


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:
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜