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

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.

Related

Pop view segue in Xcode

I have 2 UIViewControllers with their own navigation bars, but they're not embedded in a Navigation Controller. I want the bar button item of the first view to push the second view, and a bar button on the second view to pop the view, showing the first view underneath.
I've added a show segue from the first view to the second one in my storyboard but I can't find a pop segue when I try add a segue between the second view's bar button back to the first view. Here's what my storyboard looks like:
How would I make the back button on the second view pop itself to show the first view?

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.

Branching off from a tab bar controller?

I've got 3 view controllers. Two I have hooked up to a tab bar controller and one that I'm wanting to access when a user selects a cell on the second view controller in my tabbed views.
I'm wanting when the user hits "back" on the 3rd "detail" page for the user to be taken back to the 2nd view.
When I do this by just adding a button and segueing back to the 2nd VC, the tab bar is gone. I tried in my viewDidAppear to unhide the tab bar, but I guess going off of the tab bar controller messes up the navigation.
I tried creating a variable that was like "didHitBack" and on my "back" button on the 3rd view I'm creating a segue back to the Tab Bar Controller, and if "didHitBack" is true I do
_ self.tabBarController?.selectedIndex = 1
which takes me to the second page, but it's loading the first view in then going to the second page which looks bad.
I was thinking maybe there was a way to do "didHitBack" and setting the tab bar's initial view controller to the second one or something, but that all just seems very wrong.
Is there a "proper" way to do this?
To recap I have VC1 and VC2 that are hooked up to a Tab Bar Controller, I have a tableview on VC2 that on didSelectRow I'm going to VC3 which I do not want to be a part of the tabbed view controller, and when I hit back on VC3 I want to go back to VC2.
If you want to build a navigation stack, you should embed your view controller in a UINavigationController
So your tab bar would be hooked up to VC1 and NavVC. The root view controller of NavVC would be VC2.
You can then push a new view controller onto the stack using the navigation controller (or pop the view controller to go back) all within the confines of the tabBar.

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.

What is the difference between Modal and Push segue in Storyboards?

Can someone explain to me what is the exact difference between modal and push segue?
I know that when we use push the segue gets added to a stack, so when we keep using push it keeps occupying memory?
Can someone please show me how these two are implemented?
Modal segues can be created by simply ctrl-click and dragging to destination but when I do that with the push my app crashes.
I am pushing from a button to a UINavigationController that has a UIViewController.
A push Segue is adding another VC to the navigation stack. This assumes that VC that originates the push is part of the same navigation controller that the VC that is being added to the stack belongs to. Memory management is not an issue with navigation controllers and a deep stack. As long as you are taking care of objects you might be passing from one VC to another, the runtime will take care of the navigation stack. See the image for a visual indication:
A modal Segue is just one VC presenting another VC modally. The VCs don't have to be part of a navigation controller and the VC being presented modally is generally considered to be a "child" of the presenting (parent) VC. The modally presented VC is usually sans any navigation bars or tab bars. The presenting VC is also responsible for dismissing the modal VC it created and presented.
Swift 3.0 and XCode 8.2.1 update
1. Push Segue
Push segue has been renamed as Show segue. To create push segue, the parent view controller needs to be embedded in navigation controller. The navigation controller provides navigation bar. Once you connect two view controller with push segue, the child view controller will automatically has navigation bar on top. The child view controller will be added on top of the navigation stack.
Push segue also provides default features. The child view controller will have a back button that gets you back to the parent view controller. You can also swipe right to pop the child view controller. The animation for push segue is like sliding pages horizontally.
While you are allowed to make a push segue from a view controller that is not in a navigation controller, you will lose all the features like navigation bar, animation, gesture etc when you do so. In this case, you should embed your parent view controller inside navigation view controller first and then make push segue to child view controllers.
2. Modal Segue
A modal segue (i.e. present modally), on the other hand, is presenting over the current view controller. The child view controller will not inherit navigation view controller so the navigation bar will be lost if you present modal segue from a view controller with navigation view controller. You have to embed the child view controller in navigation controller again and start a brand new navigation stack if you want it back. If you want to get back to parent view controller, you have to implement this by yourself and call dismiss from code.
Animation for modal segue is that the child view controller will comes up from the bottom of the page. The navigation view controller is also gone in this demo
The push view must be built in a navigationController.
Click on your master view, then in the menu bar choose:
EDITOR->embed in->navigationController
This is pushing controls using custom push and segue methods for storyboard
And Modal is way to navigate through views without using Storyboards.

Resources