Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a storyboard view as a subview of a programmatically created view

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?

like image 959
JeffN Avatar asked Nov 15 '12 01:11

JeffN


1 Answers

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.

like image 137
KPM Avatar answered Oct 06 '22 02:10

KPM