如何在 iOS 5 中使用故事板创建自定义视图控制器容器 [英] How to create custom view controller container using storyboard in iOS 5

查看:18
本文介绍了如何在 iOS 5 中使用故事板创建自定义视图控制器容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用情节提要功能的 iOS5 中,我想创建一个自定义容器,其中嵌入了 2 个 ViewControllers.例如,将 Table 视图控制器和视图控制器都嵌入到一个 ViewController 中.

In iOS5 using storyboard feature I want to create a custom container which will have 2 ViewControllers embedded in it. For Example, embed Table view controller as well as a view controller both in one ViewController.

也就是说,一个视图控制器会有2个关系:

That is, one view controller will have 2 relationship:

  1. 到表视图控制器
  2. 查看控制器,其中将有 4 个 UIImage 视图或 UIButton

是否可以仅使用情节提要的拖放功能来创建这种类型的关系?不是以编程方式?

Is creating this type of relationship possible using storyboard's drag drop feature only & not programmatically?

推荐答案

,你应该只有一个视图控制器来控制场景.然而,这个 viewController 可能有另外两个视图控制器来控制场景中的特定子视图.为此,您在场景 viewController 中创建属性,在您的情况下,一个用于 tableViewController,另一个用于您的视图.我喜欢把东西放在一起,所以我制作了这两个 viewControllers 插座并在界面构建器中创建它们.要在界面构建器中创建它们,请从对象库中拉入一个对象并将其类型设置为相关的 viewController.将它连接到您刚刚在场景的 viewController 中创建的适当插座 - 注意:这很重要,否则如果您使用 ARC 并崩溃您的应用程序,viewController 将被释放.然后将这些 viewController 连接到您希望它们控制的视图上,您​​就完成了.

,You should only have one view controller to control the scene. However, this viewController might have two other view controllers that control particular subviews on your scene. To do this you create properties in your scene viewController, in your case one for your tableViewController and one for your view. I like to keep things together so I make both these viewControllers outlets and create them in interface builder. To create them in interface builder pull in an Object from the Object library and set its type to the relevant viewController. Hook it up to the appropriate outlet you just created in your scene's viewController - Note: this is important otherwise the viewController will be released if you are using ARC and crash your app. Then hook these viewControllers up to the view you want them to control and you are done.

如果您愿意,您也可以在场景视图控制器中实例化并跳上视图控制器.

Alternatively you can instantiate and hop up your viewControllers in your scenes viewController should you prefer to do this.

希望这会有所帮助.

经过反思,这不是一个好主意,实际上违反了 HIG,您应该为每个内容屏幕只维护一个 ViewController,而是尝试创建一个合适的视图类并让单个视图控制器处理各种观点.

On reflection this is not a good idea and actually goes against the HIG you should maintain only one ViewController for each screen of content and instead try to create a suitable view class and have the single view controller deal with the interactions between the various views.

这篇关于如何在 iOS 5 中使用故事板创建自定义视图控制器容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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