pushViewController without navigationcontroller

て烟熏妆下的殇ゞ 提交于 2019-12-18 12:58:13

问题


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.

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?


回答1:


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.

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 documentation for more information.




回答2:


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.

To dismiss the controller just call:

[self dismissViewControllerAnimated:YES completion:nil];



回答3:


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.




回答4:


I would wrap the UITableView inside a UINavigationController and just hide the UINavigationBar.

[self.navigationController setNavigationBarHidden:YES animated:NO];

And then create a back button that pops the ViewController off the stack.

[self.navigationController popViewControllerAnimated:YES]



回答5:


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:)

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.

Here are some related links to the documentation:

UINavigationController Class Reference

Customizing the Transition Animations

Presenting a Modal View Controller



来源:https://stackoverflow.com/questions/7014129/pushviewcontroller-without-navigationcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!