Xcode / Swift: How do I implement the back button?

I just started with Xcode and Swift.

I am trying to create my first small iOS app. But now I have a problem that I don’t know how to implement the back button to return to the view earlier.

My storyboard looks like this:

Storyboard

When I open the AZ view, I want to display the "Back" button, which returns me to the "Item 2" view.

To open the AZ view, I connect the Medikamente AZ button with the navigation controller.

+5
source share
4 answers

When using a storyboard, the return button is usually done by unwinding.

I usually like to follow raywenderlich sweepstakes on topics related to the user interface, for example: http://www.raywenderlich.com/113394/storyboards-tutorial-in-ios-9-part-2

It provides a detailed example of how to implement the back button in storyboards. Quote from him -

Storyboards provide an opportunity to "go back with something called the denouement that you will follow. There are three main steps: 1. Create an object for selection by the user, usually a button. 2. Create an unwind method in the controller that you want to return to. 3. Connect the method and object to the storyboard.

+4
source

When using the UINavigationController, whenever you click on the new ViewController, the back button will automatically be displayed, so you can return to the previous view manager.

So it works like: UIViewController -> UIViewController -> UIViewController

A back button will appear in the last 2 so you can go back to the previous ViewController.

You do not need to do any additional coding for the "Back" button so that it appears, it will do it on its own. Hope this clarifies the situation. Let me know if you have any questions.

+4
source

To implement the back button, your root view controller must be a navigation controller.
The first view controller becomes the root of the navigation controller's navigation.
If you want to present another view controller, you select the Show Detail link as the action for the button that the view controller should display. To do this, press Ctrl and drag the button onto the destination view controller and select "Show Part."

-1
source

I had the same problem even when the back button on the storyboard was visible during development. I removed segue and recreated it using "Show" instead of "Show detail". Changing the transition to "Show" had no effect. I think this is a mistake, so if you skip this button, delete and recreate the shogu.

-1
source

Source: https://habr.com/ru/post/1238881/


All Articles