Add subview using storyboard without external xib
Asked Answered
W

2

15

I'm learning Objective-C.

I have a problem with new storyboard feature. I would initialize a subview inside a main view with xib.

Without using storyboard, I could do it using:

controller = [[UIViewController alloc]initWithNibName:@"NibName" bundle:nil];
[self.view addSubview:controller.view];

Now, I wouldn't use an external xib, but I want manage a view in a class and use it like a subview in another class.

I know that is possible use a xib and use a similiar code to load it, but it must be out the storyboard.

Withdrew answered 28/11, 2011 at 22:11 Comment(0)
K
30

First create the view in your storyboard and then instantiate it with the following code. Also make sure you give it an identifier via the Attributes Inspector.

controller = [self.storyboard instantiateViewControllerWithIdentifier:@"identifier"];
[self.view addSubview:controller.view];
Kienan answered 29/11, 2011 at 6:27 Comment(2)
You meant "First create the view [with a View Controller] in your storyboard and then instantiate it..."Norikonorina
How about adding buttons to the identifier view(storyboard) when an UIButton is pressed in its screen?Carlacarlee
K
0

First create subview with design in some viewcontroller xib after that copy that view and paste in sub of ur viewcontroller in story board and give connections. Hope it will work.

Kudva answered 13/6, 2014 at 12:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.