• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

“嵌套”是明智的。 UIViewController里面的其他UIViewControllers像你会UIViews

用户头像
it1352
帮助1

问题说明

我有一个相当复杂的视图,对我来说,有一些托盘与自定义界面项目。他们滑进和滑出我的根视图。我想嵌套(addSubview)视图中的项目。每个都需要一些设置之前显示...和没有可以在IB中配置(它们是UIView的子类)。

I've got a fairly complex view, for me anyway, that has a few "trays" with custom interface items on them. They slide in and out of my root view. I'd like to nest (addSubview) the items inside the view. Each needs some setup before being displayed...and none can be configured in IB (they're subclasses of UIView).

我想知道为每个托盘子类化UIViewController是否有意义,然后VC的视图属性指向托盘视图,我可以填充我的自定义UIView对象。这样我可以利用viewDidLoad,等...方法在UIViewController。

I'm wondering if it makes sense to subclass UIViewController for each "tray" and then have the VC's view property point to the "tray" view which I can populate with my custom UIView objects. This way I can leverage the viewDidLoad, etc... methods in UIViewController.

我不知道别人这样做 - 至少在我看过的几个例子。这将创建一种情况,其中将有多个视图控制器被立即显示在屏幕上。从导航控制器本身向下到rootViewController和它的视图,然后任何数字(井,屏幕尺寸允许)这些小trayViewControllers。如果是,响应者链如何工作?我假设它将从最低的UIView到其包围的VC,然后到该VC的父视图,然后该视图的VC等等重复,重复..直到UIApplication ...我要求麻烦?

I'm not aware of others doing this - at least in the few samples I've looked at. It would create a situation where there would be multiple view controllers being displayed on the screen at once. from the Navigation controller itself on down to the rootViewController and its view and then any number (well, screen size permitting) of these small trayViewControllers. If so, how's the responder chain work? i assume it'd go from lowest UIView to its enclosing VC, then to that VC's parent view, then that view's VC, etc. etc. repeat, repeat.. up to UIApplication... am I asking for trouble?

或者,我只需坚持使用UIViews并将子视图添加到子视图等等。

OR, do I just stick with UIViews and adding subviews into subviews, etc. etc..

正确答案

#1

在iOS 5.0之前,这不会特别推荐,因为嵌套视图控制器的生命周期事件 - viewWillAppear等 - 不会被调用。请参见滥用UIViewControllers

Prior to iOS 5.0 this will specifically not recommended because the nested view controllers' lifecycle events – viewWillAppear, etc. – won't be called. See Abusing UIViewControllers.


一旦有多个UIViewController的视图可见,某些控制器可能不会接收到像-viewWillAppear:或-didReceiveMemoryWarning这样的重要消息。此外,他们的某些属性(如parentViewController和interfaceOrientation)可能无法按预期设置或更新。

With multiple UIViewController’s views visible at once some of those controllers may not receive important messages like -viewWillAppear: or -didReceiveMemoryWarning. Additionally some of their properties like parentViewController and interfaceOrientation may not be set or updated as expected.

iOS 5.0添加了包含UIViewControllers 通过添加子视图控制器处理这些生命周期事件。

iOS 5.0 added containment UIViewControllers that correctly handles those lifecycle events by adding child view controllers.

- (void)addChildViewController:(UIViewController *)childController

我花了无数个小时试图让嵌套视图控制器在iOS 4中工作。我最终做到了,胶水代码容易出错。然后我在文档中看到了警告。

I spent countless hours trying to get nested view controllers to work in iOS 4. I eventually did, but it required a lot of glue code that was easy to get wrong. Then I saw the warning in the docs.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhccjhek
系列文章
更多 icon
同类精品
更多 icon
继续加载