4

我想显示来自 xib 的模式对话框。显示我的窗口的代码是:

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

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

但是,当它运行时,我得到一个空白屏幕,而不是我的 ViewControllerSettings.xib 里面的内容。我想我以某种方式错误地显示了视图。任何建议表示赞赏。

编辑:

我认为这应该是

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

但由于某种原因self.navigationController是零。

编辑:

Self 是在我的 AppDelegate 中实例化的 UIViewController,如下所示:

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];
4

1 回答 1

10

您需要创建一个UINavigationController,将其根视图设置为您要呈现的 XIB 控制器(在您的情况下vcSettings,然后呈现UINavigationController

self.vcSettings =  [[ViewControllerSettings alloc] initWithNibName:@"ViewControllerSettings" bundle:nil];
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:vcSettings];
[self.navigationController presentModalViewController:controller animated:YES];
于 2012-05-05T19:52:29.353 回答