2012-05-05 63 views
4

我想从xib显示模态对话框。显示我的窗口中的代码是:从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为零。

编辑:

自我是在我的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]; 
+0

如何将方法切换为 [self presentViewController:self.vcSettings animated:YES completion:^ {{{“%@”,self.presentedViewController); }]; 什么打印在控制台上? self.presentedViewController对象是否为零? –

+1

确保viewcontroller的'view'插座连接到其xib中的根视图。 –

+0

@Vladim,谢谢,视图连接在根视图xib – dev

回答

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]; 
相关问题