I have many annotations in a mapview (with rightCalloutAccessory
buttons). The button will perform a segue from this mapview
to a tableview
. I want to pass the tableview
a different object (that holds data) depending on which callout button was clicked.
For example: (totally made up)
- annotation1 (Austin) -> pass data obj 1 (relevant to Austin)
- annotation2 (Dallas) -> pass data obj 2 (relevant to Dallas)
- annotation3 (Houston) -> pass data obj 3 and so on… (you get the
idea)
I am able to detect which callout button was clicked.
I'm using prepareForSegue
: to pass the data obj to the destination ViewController
. Since I cannot make this call take an extra argument for the data obj I require, what are some elegant ways to achieve the same effect (dynamic data obj)?
Any tip would be appreciated.
Best Answer
Simply grab a reference to the target view controller in
prepareForSegue:
method and pass any objects you need to there. Here's an example...REVISION: You can also use
performSegueWithIdentifier:sender:
method to activate the transition to a new view based on a selection or button press.For instance, consider I had two view controllers. The first contains three buttons and the second needs to know which of those buttons has been pressed before the transition. You could wire the buttons up to an
IBAction
in your code which usesperformSegueWithIdentifier:
method, like this...EDIT: The demo application I originally attached is now six years old, so I've removed it to avoid any confusion.