组合现有视图/控制器的最佳方式?

发布于 2024-09-17 12:48:01 字数 228 浏览 18 评论 0原文

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

现在,我想创建一个新屏幕,它是一种“比较”屏幕,结合了这些现有视图中的两个。因此,用户可以看到两个不同曲线的图表并分别与每个图表进行交互。我认为如果使用确切的现有视图,只需调整大小以适应一半的空间就可以了。

对于在最大化重用的同时解决这个问题的最佳方法有什么意见吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你另情深 2024-09-24 12:48:01

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

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

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

  • viewWillAppear:animated:
  • viewDidAppear:animated:
  • viewWillDisappear :动画:
  • viewDidDisappear:动画:

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:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文