0

I have a table view which uses a fetchedResultsController to manage a series of 'Venue' objects from core data. When you select one of the rows on the table view, it passes the current Venue object to a new view (via prepareForSegue), which displays details of the Venue object: name, address, images etc. This all works fine.

I have something I want to achieve but I'm not sure the best or most conventional way to do it. I would like the same behaviour as above, but with a map view sandwiched in between the initial table view and the detail view. So the navigation stack looks like this:

table view (showing all Venues) -> map view (showing all Venues) -> detail view (showing one selected Venue)

Presently I have a button from the table view which segues to the map view, passing an array of annotations which are then plotted on the map. The annotations don't contain all the Venue information, they are just assigned a title and subtitle from each Venue. Each annotation shows a detail disclosure button linking to the detail view. However I am conceptually stuck as to how to pass the relevant Venue object (currently only available in my table view) to the detail view when selected from the map view.

My assumption is that I need to do something along these lines: pass all the Venue objects from my table view to my map view, and just have them existing in the background but not being used. Then when a disclosure button is pressed, the map view checks somehow which Venue matches the selected annotation (checking if the title attribute matches perhaps?) and passes that onto the detail view as the 'selected Venue'. However I don't know how best to do this in practice or even if I have the right idea. Is it possible for my annotation to contain the entire related Venue object? Or for the detail view to somehow ask the initial table view for data?

Hope I'm explaining this clearly enough. Sorry its a bit wordy. I'm still fairly new to Xcode and understand that I may be overlooking something very simple, or making a fundamental error somewhere. Any advice would be much appreciated though!

Wain
  • 118,658
  • 15
  • 128
  • 151
Kapungo
  • 59
  • 6
  • Why wouldn't you present the table and map in tabs or something? Why would you view all on a map after selection one? – Wain Feb 27 '14 at 12:53
  • Maybe I wasn't clear, sorry. From the table view you can select a single venue, but there is also a button called 'show all' which presents the same venues on the map. A single one is then selected before the detail view is shown. – Kapungo Feb 27 '14 at 13:51
  • So there seems to be no reason to pass anything from the table to the map, no? – Wain Feb 27 '14 at 13:53
  • check the below post http://stackoverflow.com/questions/7864371/ios-how-to-pass-prepareforsegue-an-object – Feras Farhan Feb 27 '14 at 13:58

3 Answers3

1

If you only have one selected object, just pass that on to the map view. The map view can use its own fetched results controller to get whatever other data it needs from the data store (presumably the order of importance could be different from the table view).

You could associated the venue objects with the annotations, but it seems that you only specifically need the one venue to pass to the detail view so it should just be stored as an instance variable.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • This would work, although what I really need is for the map view to show *all* the venues, and then for the user to select one to view the details of. So they aren't selecting a single venue from the initial table view (that behaviour is possible but I already have it covered). – Kapungo Feb 27 '14 at 13:50
  • 1
    So why do you say that the table view comes before the map? They should be alternatives, each of which can show the detail view with the selected item. The map should still have its own FRC, associate the index path for each item with the annotations and use that to request from the FRC. – Wain Feb 27 '14 at 13:53
  • Good point. I think it could be my fundamental newbie error that meant I didn't build the map view this way. I will try what you suggest and report back. – Kapungo Feb 27 '14 at 13:56
  • Perhaps a tab bar controller or the use of a segmented control would help in this case (maybe in the nav bar instead of the button you currently have). – Wain Feb 27 '14 at 13:57
0

Create a model where you query a venue by its name/id or something. Then when you go in the last detail view pass the venue name/id to it from the map view. Or, as you are suggesting in your question, pass the whole venue object to your map view, use whatever you want from this object in this view and when you segue to the detail view pass the whole object again.

Ed Liss
  • 546
  • 4
  • 16
0

you post your data therw -prepareForSegue check the below post

How to pass prepareForSegue: an object

and you can check the below storyboard example

https://github.com/pandamonia/A2StoryboardSegueContext

Community
  • 1
  • 1