ios 没有导航控制器的 pushViewController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7014129/
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
pushViewController without navigationcontroller
提问by dubbeat
I have a class that is of type UITableViewController
.
This class has a member of type UINavigationBar
that I use for adding in an edit button for the table view.
我有一个类型为 的类UITableViewController
。这个类有一个UINavigationBar
我用来为表格视图添加编辑按钮的类型成员。
Using this method calling is invalid.
使用这种方法调用是无效的。
[self.navigationController pushViewController:controller];
How can I push a detail view onto the view after selecting a table row without wrapping my UITableViewController
in a UINavigationController
?
选择表格行后如何将详细视图推送到视图上而不将我的包裹UITableViewController
在 a 中UINavigationController
?
采纳答案by Anomie
You can't push a view controller onto a navigation controller if there is no navigation controller. If you are wanting to be pushing controllers and have it display the topmost controller and everything, just use a UINavigationController and be done with it.
如果没有导航控制器,则无法将视图控制器推送到导航控制器上。如果您想要推送控制器并让它显示最顶层的控制器和所有内容,只需使用 UINavigationController 并完成它。
You can push arbitrary UINavigationItems onto your UINavigationBar, and your bar's delegate will be notified when the user uses the back button so you can take appropriate action. See the documentationfor more information.
您可以将任意UINavigationItem推送到您的 UINavigationBar 上,当用户使用后退按钮时,您的栏的委托将收到通知,以便您可以采取适当的行动。有关更多信息,请参阅文档。
回答by Filip Radelic
The closest alternative if you don't want to use navigation controller are modal view controllers.
如果您不想使用导航控制器,最接近的选择是模态视图控制器。
[self presentViewController:controller animated:YES completion:nil];
This will slide the controller into your screen from bottom, or if you change controller's modalTransitionStyle
it can flip over or fade in.
这会将控制器从底部滑入屏幕,或者如果您更改控制器,modalTransitionStyle
它可以翻转或淡入。
To dismiss the controller just call:
要关闭控制器,只需调用:
[self dismissViewControllerAnimated:YES completion:nil];
回答by José
What could also be done is to use a Navigation Controller as usual and then hide it.
还可以做的是像往常一样使用导航控制器,然后将其隐藏。
To hide the Navigation Controller using storyboards: select it and uncheck "Show Navigation Bar" in the attribute inspector. Others might suggest to hide the navigation bar in each controller, but the problem with that is that it will appear for a millisecond and then disappear.
要使用故事板隐藏导航控制器:选择它并在属性检查器中取消选中“显示导航栏”。其他人可能会建议在每个控制器中隐藏导航栏,但问题在于它会出现一毫秒然后消失。
回答by Petter
I would wrap the UITableView inside a UINavigationController and just hide the UINavigationBar.
我会将 UITableView 包装在 UINavigationController 中,然后隐藏 UINavigationBar。
[self.navigationController setNavigationBarHidden:YES animated:NO];
And then create a back button that pops the ViewController off the stack.
然后创建一个后退按钮,将 ViewController 从堆栈中弹出。
[self.navigationController popViewControllerAnimated:YES]
回答by Joe149
It's true that without a UINavigationController
you can not push view controllers. You rather present view controllers modally via UIViewController.present(_ viewControllerToPresent:, animated:, completion:)
确实,没有 aUINavigationController
你不能推送视图控制器。您宁愿通过模态呈现视图控制器 UIViewController.present(_ viewControllerToPresent:, animated:, completion:)
But it's possible to create a custom segue to display the view controller as if it were a push (or any other animation you want), although it seems that using a UINavigationController
just makes things easier.
但是可以创建一个自定义的 segue 来显示视图控制器,就好像它是一个推送(或任何其他你想要的动画),尽管似乎使用 aUINavigationController
只是让事情变得更容易。
Here are some related links to the documentation:
以下是该文档的一些相关链接:
UINavigationController Class Reference
Customizing the Transition Animations