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

问题描述

在使用storyboard功能的iOS5中,我想创建一个自定义容器,其中嵌入了2 ViewControllers 。例如,在一个 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 其中

  1. to table view controller
  2. to view controller which in turn will have 4 UIImage view Or UIButton in it

创建这种类型的关系只能使用storyboard的拖放功能和&不是以编程方式?

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

推荐答案

,您应该只有一个视图控制器来控制场景。但是,此viewController可能有两个其他视图控制器来控制场景中的特定子视图。为此,您需要在场景viewController中创建属性,在您的情况下为tableViewController创建属性,为视图创建一个属性。我喜欢把事情放在一起所以我创建了这些viewControllers插件并在界面构建器中创建它们。要在界面构建器中创建它们,请从Object库中提取Object,并将其类型设置为相关的viewController。将它连接到您刚刚在场景的viewController中创建的相应插座 - 注意:这很重要,否则如果您使用ARC并使应用程序崩溃,则会释放viewController。然后将这些viewControllers挂钩到你希望它们控制的视图,你就完成了。

,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.

或者你可以在你的场景中实例化和跳转你的viewControllers viewController你喜欢什么这样做。

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中使用故事板创建自定义视图控制器容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 01:22