Anatolii Rudenko
Anatolii Rudenko

Reputation: 416

go back to a certain viewController

my Storyboard looks like:

User can go directly from the 1st screen to the 4th. The fourth screen contains tableView, with XIB cell design. I want user to be able to tap on a cell and get to the 3rd screen and send some data with that. I know this should be done in didSelectRowAt. But is it even possible?

Upvotes: 0

Views: 53

Answers (1)

Eric Hua
Eric Hua

Reputation: 1015

Yes it is possible.

  1. Create a segue. In your storyboard, ctrl-drag from the first button on top of your 4th screen to anywhere on your second screen. You should see a new segue created in your storyboard.
  2. Give the segue an id. Click on the newly created segue, in the right panel, set the indentifier attribute under the Indentity Inspector tab.
  3. Perform the segue. In your didSelectRowAt, add the following line:
self.performSegue(withIdentifier: "THE_ID_YOU_ASSIGNED_IN_STEP_2")
  1. Send data to the destination segue. In your screen 4 view controller, add the following function:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "THE_ID_YOU_ASSIGNED_IN_STEP_2" {
        if let destinationVC = segue.destination as? YOUR_SCREEN_3_VC {
            // Send data to your VC, such as assigning values
        }
    }
}

Upvotes: 1

Related Questions