Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Presenting Modal View Controller From Xib

I would like to show a modal dialog from a xib. The code that shows my window is:

self.vcSettings = [[ViewControllerSettings alloc] initWithNibName:@"ViewControllerSettings" bundle:[NSBundle mainBundle]];  

[self presentModalViewController:self.vcSettings animated:YES];

When this runs though, I get a blank screen, and not what was inside of my ViewControllerSettings.xib. I imagine I'm showing the view incorrectly somehow. Any advice is appreciated.

EDIT:

I think this should be

[self.navigationController presentModalViewController:self.vcSettings animated:YES];

but for some reason self.navigationController is nil.

EDIT:

Self is a UIViewController instantiated in my AppDelegate like so:

UIViewController* viewMain = [[ViewController_iPhone alloc]     initWithNibName:@"ViewController_iPhone" bundle:nil];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = viewMain;
[self.window makeKeyAndVisible];
like image 766
dev Avatar asked Dec 27 '22 01:12

dev


1 Answers

You need to create a UINavigationController, set it's root view to the XIB controller that you want to present (in your case vcSettings), then present the UINavigationController

self.vcSettings =  [[ViewControllerSettings alloc] initWithNibName:@"ViewControllerSettings" bundle:nil];
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:vcSettings];
[self.navigationController presentModalViewController:controller animated:YES];
like image 142
WrightsCS Avatar answered Jan 04 '23 22:01

WrightsCS