简体   繁体   English

使用Storyboard作为子视图?

[英]Using a Storyboard as a subview?

I am creating a project in which I'm creating my own custom navigation system by animating subviews on and off screen. 我正在创建一个项目,我通过在屏幕上和屏幕外设置子视图来创建我自己的自定义导航系统。 One of these subviews is to have a navigation controller, and many other elements that are far easier (in this case) to create with storyboards. 其中一个子视图是使用导航控制器,以及使用故事板创建更容易(在这种情况下)的许多其他元素。 I have tried adding a storyboard as a subView with the following code (with little luck). 我尝试使用以下代码添加故事板作为子视图(运气不佳)。

MainSV = [self.storyboard instantiateViewControllerWithIdentifier:@"MainSubView"];

[self.view addSubview:MainSV];

I am receiving the following warning. 我收到以下警告。

Incompatible pointer types sending 'UIStoryboard *__strong' to parameter of type UIView*' 不兼容的指针类型将'UIStoryboard * __ strong'发送到UIView *'类型的参数

Now I'm not arguing that the above code should be working or anything because I understand the error, so what I'm asking is, how can I through this method or any other, add a storyboard as a subview of my UIView ? 现在我并不是说上面的代码应该正常工作,因为我理解错误,所以我要问的是,如何通过这种方法或其他任何方式添加故事板作为我的UIView的子视图? Can anyone point me in the right direction on this one? 谁能指出我在这个方向上的正确方向?

You will need to use the containment view controller API, which is only available in iOS 5: 您将需要使用仅在iOS 5中可用的包含视图控制器API:

[self addChildViewController:mainSV];
[self.view addSubview:mainSV.view];

You can read the gotchas etc. in the documentation: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html 您可以阅读文档中的陷阱等: http//developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM