将故事板视图添加为以编程方式创建的视图的子视图 [英] Add a storyboard view as a subview of a programmatically created view

查看:96
本文介绍了将故事板视图添加为以编程方式创建的视图的子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个特殊类的UIView具有某些属性,我这样做编程,因为它通常是空白的,但有时会包含其他视图。我知道如果我以编程方式创建一个UIView,我可以做一些 [specialView addSubview:aView];



问题是有一个UIView,我在故事板中创建,我需要添加UIView作为一个子视图在我的特殊视图。我已经连接它作为属性在我的ViewController,但当我做同样的代码,上面,没有任何反应。

$

  MyViewController * myViewController = [self.storyboard instantiateViewControllerWithIdentifier:@MyScene ]; 
[specialView addSubView:myViewController.theViewToAdd];

并且不要忘记在Interface Builder中给你的场景


I have created a special class of UIView that has certain properties, and I did so programmatically because it is usually blank but will at times contain other views. I know that if I create a UIView programmatically I can do something like [specialView addSubview: aView];

My problem is that there is a UIView that I created in storyboard and I need to add that UIView as a subview on my special view. I have connected it as a property in my ViewController but when I do the same code as above, nothing happens. Thoughts?

解决方案

MyViewController *myViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MyScene"]; 
[specialView addSubView:myViewController.theViewToAdd]; 

And don't forget to give such an identifier to your scene (view controller) in Interface Builder.

这篇关于将故事板视图添加为以编程方式创建的视图的子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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