Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pushViewController without navigationcontroller

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?

like image 423
dubbeat Avatar asked Aug 10 '11 16:08

dubbeat


5 Answers

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];
like image 71
Filip Radelic Avatar answered Oct 12 '22 12:10

Filip Radelic


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]
like image 35
Petter Avatar answered Oct 12 '22 12:10

Petter


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.

Navigation Controller attributes tab

like image 25
José Avatar answered Oct 12 '22 13:10

José


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.

like image 24
Anomie Avatar answered Oct 12 '22 14:10

Anomie


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

like image 43
Joe149 Avatar answered Oct 12 '22 14:10

Joe149