I’ve created an almost-empty UIViewController class named MyViewController. In the viewDidLoad I’m setting the title and adding a close-button to the navigationItem.leftBarButtonItem.
I’m presenting my MyViewController like this:
MyViewController *myViewController = [[MyViewController alloc] init];
UINavigationController *nc = [[UINavigationController alloc] myViewController];
nc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:nc animated:YES];
When the viewController is presented, the background of it’s view is just black. How can I setup it’s view to fill-out the screen with an empty view — just like when the UIViewController is setup in a Storyboard?
I’ve tried adding the following to the viewDidLoad, but the view is still black:
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
By default a VC’s view gets created in
-loadViewwhich you usually neither call, nor override. It gets called automatically the first time you request the the VC’sviewproperty.The view’s size is automatically set to the ’empty space’, like everything except for the status bar without a NavigationController, minus the navbar when using one etc. You shouldn’t worry about its size – usually it’s just fine.
You can add your own views in
-viewDidLoadand remove them again (for low-memory reasons) in-viewDidUnload.