Go back from pushed navigation controller - ios

Screenshot below is of a sample xCode Master Detail project. I put a Delete button on the Detail scene's navigation bar.
When I tap this button, I want the Detail view to close and go back to the Master view. This is the code:
-(IBAction)delete:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
It does not work. The default back button on the navigation bar does. How do you close a view that has been pushed from accessory action?
Note, the above storyboard comes with the Master-Detail Application template:

You can always get back to the root by calling
[self.navigationController popToRootViewControllerAnimated:YES];
In your case, the problem is that you are pushing second navigation controller onto the navigation stack and it looks like this:
navigation controller -> table view controller -> navigation controller -> detail view controller
You should directly segue from the table view to the detail view so the navigation stack looks like:
navigation controller -> table view controller -> detail view controller

Related

Why Do I Need A Second Navigation Controller?

I have the following on my storyboard:
A navigation controller with a table view controller as its root view controller.
The table view controller's navigation item has right bar button (Add) that segues to a 2nd navigation controller.
The 2nd navigation controller has a 2nd table view controller as its root view controller.
The 2nd table view controller's navigation item has a left bar button (Cancel) and a right bar button (Save) both of which unwind back to the 1rst table view controller.
This all works fine: I can navigate from the 1st table view controller to the 2nd and back.
If I remove the 2nd navigation controller and instead segue directly from the 1st table view controller to the 2nd then the 2nd table view controller's navigation item is not displayed. What is going on? Why do I need the 2nd navigation controller?
remove the intermediate navigation controller and connect your second VC to initial vc and change your segue type kind model from present modally to show e.g push
if you are using present then navigation controller is not a manodatry but on your save and cancel button purpose you need to embed with navigation controller, in here you push then no need of Second Navigation Controller.
on navigation use
[self performSegueWithIdentifier: #"sample" sender: self];
on your second by default navigation bar will comes, if you need add barbuttons in right and left side, once press the done button use the following comment
[self.navigationController popToRootViewControllerAnimated:YES];
it automatically come back to initial VC,
you can get the detail of segues in apple
You don't need a second navigation controller. This is what you need to do to after you do a Show segue to the second TableViewController:
Confirm that you're actually doing a Show (e.g., Push) segue. If you have to do a Present Modally segue, then you will need another UINavigationController.
Add a Navigation Item (not a Navigation BAR) to the second TableViewController. You'll then be able to add a title, add navigation buttons, etc.

Navigation bar is empty, created from storyboard

This is my story board:
Whenever I jump to a view controller embedded in navigation controller, the navigation bar is shown but empty, why?
The sequence I created it is:
connect buttons with destination view controllers
embed destination view controllers in navigation view controller
And the segue I use is present modally - cross dissolve.
The First root controllers of a navigation controller won't have any Back button attached to its navigation bar. You should add an additional View Controller next to any root View Controller of Navigation Controller with Push Segue ( or Show Segue for newer IOS ) to navigate between them.
I tested different segue transition methods with test projects, the answer I got is: if you are transitioning by presenting it modally, you don't get the back button, you only get it by push.

Navigation Tab Bar Controller to UIView Controller?

I am using tab bar controller and i want to push uiview controller over tab bar controller. but i don't know how we push UIView controller over Tab Bar Controller. Thanks
You need to embed a navigation controller in your tab bar controller screen where you want the push set up to work
If I'm reading your question right, you want to push a view controller over another view controller which is currently displaying tabs.
In this case, I believe you would need a UINavigationController as your root view controller. Inside this navigation controller, you would initially push a UITabController with it's associated view controllers per tab. When it's time to push another view controller over the tab controller, create an instance of the view controller to push and use the following code:
[self.navigationController pushViewController:newViewController animated:YES];
This will push the new view controller over the existing TabController that is currently being displayed.
The question is little vague Hence I will add the two way to push to another view controller we use in common.
From navigation controller : You just need to create an UIButton in the navigation controller and then control + drag the button to another view controller to create a push feature to another screen in storyboard.
From Tab view Controller : Similarly, control key + drag the tab bar item in the tab bar controller to another UIView controller in the story board. Then chose 'show' option to create a push to another UIview controller screen.
Hope this helps.
Tab Bar controller is different and Navigation Bar controller is different.
And as Pittmaster says, your navigation view controller should be root view controller.

Navigating to a Navigation view controller via button

I have a master detail class that has a navigation view controller. I have created another view controller which I want to use to load the navigation view controller via a button. I have added a view controller and have linked a button to the navigation view controller however when i test to see if the new view loads, I receive an error on the main.m
What am i doing wrong?
I think you need not take another navigation controller if you have navigation controller for the view controller having button and you can directly take view controller which you want (UITableviewController or UIViewController). Give connection from your button to that view controller

(iOS) Why does second 'push' segue in navigation controller always crash?

I have a storyboard setup as a Tabbed Application with first view controller containing a
UITableView. The Protoype cell has a "push" segue to detail view which is embedded in a navigation controller. So far so good. The detail view pushes when a cell is selected and there is a navigation bar item to get back to the table view.
Now I run into trouble. The detail view has 2 buttons "Map" and "Ticket". If I create a new UIViewController, embed it in a navigation controller, and ctril-drag a 'push' segue from a button to the new view controller as before, the app crashes instantly with a SIGABRT when I click the button. If I don't embed in nav controller and use a 'modal' segue instead it doesn't crash but it seems a natural flow to continue with the 'horizontal slide' animation and the nav bar button back to the detail view.
Once I can stop that crashing I would like to connect the other button to it's own view controller with a UIMapView.
What am I doing wrong?
You don't need to embed a navigation controller in the detail view. You only need one at the top level. Take out the navigation controller in the detail view controller and just do a push from there to the next view.

Resources