2010-08-13 118 views
13

仍然无法弄清楚我做错了什么。试图用导航控制器获取模态视图。模态浏览导航控制器

这里是我的项目 http://www.matthewpateman.com/New.zip

谁能告诉我什么,我做错了什么?我想“ShopModalView.xib”导航器弹出,但它只是diplaying一个空白页...

+1

请评论或更新您刚才的问题,而不是简单地张贴另一个。 – Justin 2010-08-13 17:20:43

+0

你说得对。对不起...... – 2010-08-13 17:25:21

+6

也没人愿意下载一个潜在的恶意zip。使用http://gist.github.com/或friendpaste或其他东西来显示相关的代码 – 2010-08-13 17:29:14

回答

44

目前它作为一个模式视图,敷控制器导航控制器,可提供导航栏要添加编辑,保存箱等按钮

ModalViewController *modalController = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil]; 
modalController.delegate = self; // Set any delegate you may have 

// This is where you wrap the view up nicely in a navigation controller 
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:modalController]; 

// You can even set the style of stuff before you show it 
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; 

// And now you want to present the view in a modal fashion 
[self presentModalViewController:navigationController animated:YES completion:nil]; 
+0

哇!谢谢你的帮助!这非常有帮助。真的很感谢你花时间修复它。如你所说!很好 - 很好,很简单。 – 2010-08-13 22:56:23

+1

不是一个概率,但要确保你学到了一些经验教训:你在XCode中缺少一些视图控制器的XIB文件,你错过了一个MainWindow.xib,这就是为什么你得到一个'NSInternalInconsistencyException'错误(它有“applicationDidFinishLaunching”中没有任何内容加载,最初也没有办法设置导航控制器)。您还隐藏了导航控制栏,不会显示您的视图何时出现。保持您的XIB的命名与处理它们的视图控制器类相同......这是一件不需要记住的事情。 – iwasrobbed 2010-08-14 00:56:06

+0

您可能希望创建一个全新的示例项目,并且现在您可以自行设置它,以便您有一些工作要做。 XCode实际上有一个导航控制器模板,如果你知道从一开始你就会使用它(XCode - > New project - > iPhone OS application - > Navigation based app - > uncheck“Use core data for storage”) – iwasrobbed 2010-08-14 00:59:01

3
ShopModalViewController *shopMVC = [[ShopModalViewController alloc] initWithNibName:@"ShopModalViewController" bundle:nil]; 
//set properties 
UINavigationContrller *navCon = [[UINavigationController alloc] initWithRootViewController:shopMVC]; 
[self presentModalViewController:navCon animated:YES]; 
[shopMVC release]; 
[navCon release]; 
+0

我用你的代码,但它给了我这个错误信息: 2010-08-13 19:55:54.718导航[95599:207] ***终止应用程序由于未捕获的异常'NSInternalInconsistencyException',原因:'无法在包中加载NIB: – 2010-08-13 18:57:23

2

对于那些想要做到这一点斯威夫特3.X:

// Obtain your viewcontroller 
let viewController = ... 

// Initialize a navigation controller, with your view controller as its root 
let navigationController = UINavigationController(rootViewController: viewController) 
navigationController.navigationBar.barStyle = .blackTranslucent 

// Present it modally from the current controller 
present(navigationController, animated: true, completion: nil) 
+0

谢谢,它适用于我正在寻找的内容。 – Hoan 2017-12-17 01:49:58