本文介绍了“嵌套”是明智的。 UIViewController里面的其他UIViewControllers像你会UIViews?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当复杂的视图,对我来说,有一些托盘与自定义界面项目。他们滑进和滑出我的根视图。我想嵌套(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..

推荐答案

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

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.

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

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.

这篇关于“嵌套”是明智的。 UIViewController里面的其他UIViewControllers像你会UIViews?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:56