Reputation: 21
Using storyboards I am trying to overlay a UIViewController
on top of a current View
.
In my FirstViewController
I import the SecondViewController.h
and then run the following in the viewDidLoad
method
SecondViewController *overlay = [[SecondViewController alloc]init];
overlay.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
[self addChildViewController:overlay];
[self.view addSubview:overlay.view];
[overlay didMoveToParentViewController:self];
[self.view bringSubviewToFront:overlay.view];
In my SecondViewController.h
viewDidLoad
method I have an output to NSLog
which is getting displayed in the console when I run the app, however the second view is not being display on top of the first. So the SecondViewController
is getting added but not displayed. What is it am I missing?
Essentially I want the SecondViewController
to have transparent background so I can do a fancy alert message that displays information, and you can still see the FirstViewController
behind it.
Thanks
Upvotes: 1
Views: 1075
Reputation: 1045
First set the identifier of secondViewController and the use the simple code:
secondViewController *overlay = [self.storyboard instantiateViewControllerWithIdentifier:@"secondViewController"];
overlay.view.frame = CGRectMake(100, 100, 100, 200);
[self.view addSubview:overlay.view];
In my case the identifier is same as class name that is "secondViewController".
Upvotes: 1