2

I have 3 tabs with tab bar controllers. All the 3 view controllers in the tab bar have navigation controllers to go to other view controllers on their own.

One of the view controllers in the tab bar is with the map and map annotations(map view controller). Those annotations come from the web service based on the current location when the app starts. In the map view controller, there is a navigation bar item(search button) at the top to enable you to search the map for different location. Once you click the search button, the search view controller is pushed on to the navigation stack. After the search is done and new location is found, the new location is presented in the table view in the same search view controller.

My goal is to go back to the map view automatically once the table view item is clicked, and to load the new annotation data on the map based on the newly searched location. Once the map view is displayed again, the old data which were retrieved when the app first started should be replaced with new data obtained from the web. All the 3 view controllers in the tab bar share the annotation data through singleton object.

My question is, what should I do to go back to map view with new data when the user clicks the item in the didSelectRowAtIndexPath method in the search view controller? What is the best way to go back to map view in the tab bar and to load the data again from the web service?

Do I use the 'popViewControllerAnimated' in the search view controller and and then do work in the map view controller 'viewWillAppear' method? How do I pass the latitude and longitude values of the new location to the map view controller from the search view controller? Do I import the map view controller into the search view controller and set the ivar of the map view controller for the latitude and longitude even though the 'search view controller' came into being by being pushed by the 'map view controller'? What is the complication of importing the map view controller into the search view controller since the map view controller is already in the memory?

What I am trying to accomplish is similar to what the free app 'Wikihood' is doing when it searches the map.

Thank you very much.

user1026669
  • 143
  • 3
  • 14

1 Answers1

0

It seems that you could use your singleton object as the data model. That way, viewWillAppear: just shows whatever location is currently set in the data model and your search controller has a convenient place to put its results.

The other options that come to mind would be a delegate or notification but since you already have the model object, it would be consistent to keep using it.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • Thank you very very much for the speedy reply. I thought about the singleton object for this purpose, but I thought there would be a better way. I will try using the singleton object to store the latitude and longitude values. Do you just use the 'popViewControllerAnimated' to go back to map view to trigger the refresh, or is there any better way? Thank you. – user1026669 Apr 06 '12 at 22:13
  • If you used push to get it there, pop is the normal way back. If there's another way at all, it's probably not better. :) – Phillip Mills Apr 06 '12 at 22:16
  • BTW, as you suggested, I put the lat and lon data into the sigleton object, and it works very well. And it is logically very fit. Thank you very much. – user1026669 Apr 06 '12 at 23:43
  • Good to hear. If you hadn't already been using a singleton, I probably wouldn't have suggested it because delegates are more elegant but, since you already had one, why not.... – Phillip Mills Apr 06 '12 at 23:50