Reputation: 7585
I am just starting out on iOS(from Android) and I am having trouble figuring out how to pass data between views in tabs. I've included pictures to describe my question in a little more detail; how can I get the map type to change when one of the selectors is changed or the user location to appear/disappear when the boolean switch is ticked?
One tab is a map tab:
The Other is a selector:
Upvotes: 0
Views: 5466
Reputation: 6353
You should check out this thread for a very detailed description of each possible method:
What's the best way to communicate between view controllers?
Upvotes: 2
Reputation: 5953
Well, my first answer would be that a tabbed interface probably isn't appropriate here. Tab bars are to provide parallel modes of usage (e.g a watch app that shows either an alarm or a timer), not to provide subsidiary information. You should probably have a button on the mapview that pulls up a modal dialog to change the settings. That then uses a delegate pattern to send the changed information back to the parent. See apple's document on Modal View Controllers for sample code.
Upvotes: 0
Reputation: 150605
The quick answer is that you have the view controllers talk to each other.
Edit: I knew I'd have to come back.
It depends on where you are starting from.
But This thread seems to be popular and has an example project. It might need tweaking to use a more modern iOS version - but it does provide the general idea.
One way to do it in your application, is to have properties on the view controller that shows the map as to the type of view it displays, and whether or not the current location is shown. Then, from your selector's view controller set those properties.
How do you get the map's view controller - pass it to the selector's controller at creation. Resist the temptation to have the map controller be a property of the Application delegate. It's an easy way of passing it around, but it breaks encapsulation IMO.
As an aside.
As you progress, you'll realise that the way to do this is to have the controls overlaid on the map view as subviews. Not only is that a better UI (all the changes can be made in place), but then as you are on the same view, you don't need to use a different view controller, and there is no need to be passing around object pointers. :)
Upvotes: 3
Reputation: 301
For this type of "Settings" view, I'd create a custom protocol and set your map view as the delegate object in your settings view. Let me know if you need code.
Upvotes: 0
Reputation: 12325
You will have to use NSNotifications
or NSUserDefaults
Check objective-c updating data from a different view
Upvotes: 1