合并现有视图/控制器的最佳方法? [英] Best way to combine existing views/controllers?

查看:65
本文介绍了合并现有视图/控制器的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的iPhone View Controller,带有一个显示交互式图形的相应视图(通过笔尖).用户可以触摸光标点以沿曲线移动并获取与触摸点相对应的数据.

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?

推荐答案

Apple的文档建议在iPhone的每个屏幕上仅使用一个视图控制器.该框架并不是真正为每个屏幕支持多个视图控制器而设计的,但是如果小心一点,您可以不使用它.

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.

我建议创建一个CompositeViewController类,其中包含对两个子视图控制器的引用. CompositeViewController的视图设置为全屏包装器视图.每个子视图控制器的视图都设置为适当的子视图.

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.

完成这项工作的关键是将某些调用从CompositeViewController手动委派给子视图控制器.特别是,如果希望在子视图控制器上调用这些方法,则需要委派这些方法:

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:
  • viewWillAppear:animated:
  • viewDidAppear:animated:
  • viewWillDisappear:animated:
  • viewDidDisappear:animated:

这篇关于合并现有视图/控制器的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆