Nitish
Nitish

Reputation: 14113

Add Storyboard as subview in UIViewController

I am creating a reusable view for which I have created a separate Storyboard. This reusable view will be added in different UIViewController is Main.StoryBoard. For this I followed storyboard reference. But I am not sure how to add Storyboard as a subview inside a UIViewController having some definite frame.
Please let me know if you want to have a screenshot as to how I am designing the screen.

Upvotes: 2

Views: 227

Answers (2)

ajay_nasa
ajay_nasa

Reputation: 2298

make reusable UIViewController and then addChildViewController wherever you want. Below i made RemarksViewController which i used in many views of UIViewController

    RemarksViewController *vC=[[UIStoryboard storyboardWithName:@"yourStoryboardName" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"showRemarks"];
    [self addChildViewController:vC];
    vC.view.bounds=self.view.bounds;
    [self.view addSubview:vC.view];
    [vC didMoveToParentViewController:self];

Upvotes: 0

Rahul Patel
Rahul Patel

Reputation: 1832

first you need to get the reference of the storyboard from the different storyboard.

UIViewController *viewControllerToAdd =
    [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]instantiateViewControllerWithIdentifier:@"viewForPopover"];

//Instead of MainStoryboard you write the name of the Storyboard which you have created separately

the you write these lines

[self addChildViewController:viewControllerToAdd];
[self.view addSubview:viewControllerToAdd.view];
[viewControllerToAdd didMoveToParentViewController:self]; 

This much should probably do, i havent tried it yet

Upvotes: 2

Related Questions