0

I created a UIBarButtonItem in my View Controller. In my Storyboard, I control clicked the UIBarButtonItem and dragged it to a new view controller which pushes the new View Controller into the navigation stack when I click the UIBarButtonItem.

My problem is when I click on the button, I want to pass the view controller data before it's presented. I'm not entirely sure if I should be abandoning Storyboards to make this happen and handle everything in code or if there is a way to override some method(s) to facilitate this?

0

1 Answer 1

1

Check out prepare(for: UIStoryboardSegue). You'd override this in your calling view controller and access the destination view controller here.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "MySegue",
        let destinationViewController = segue.destination as? DetailViewController
        destinationViewController.object = selectedObject
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.