ios 带导航控制器的模态视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3479231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Modal View with Navigation Controller
提问by Matthew Pateman
still cannot figure out what I am doing wrong. Just trying to get a modal view with a navigation controller inside.
仍然无法弄清楚我做错了什么。只是想获得一个带有导航控制器的模态视图。
Here is my project http://www.matthewpateman.com/New.zip
这是我的项目 http://www.matthewpateman.com/New.zip
Can anybody tell me what I am doing wrong? I want "ShopModalView.xib" to pop up in the navigation controller, but its just diplaying a blank page…
谁能告诉我我做错了什么?我想在导航控制器中弹出“ShopModalView.xib”,但它只是显示一个空白页面......
回答by iwasrobbed
Present it as a modal view and wrap the controller in a navigation controller to provide a navigation bar in case you want to add edit, save, etc buttons
将其呈现为模态视图并将控制器包装在导航控制器中以提供导航栏,以防您想添加编辑、保存等按钮
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];
回答by DVG
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];
回答by CodeBender
For those wanting to do this in Swift 3.x:
对于那些想在 Swift 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)