Graphics Programs Reference
In-Depth Information
In WhereamiViewController.m , add the following line of code to
changeMapType: .
- (IBAction)changeMapType:(id)sender
{
[[NSUserDefaults standardUserDefaults]
setInteger:[sender selectedSegmentIndex]
forKey:WhereamiMapTypePrefKey];
switch([sender selectedSegmentIndex])
{
case 0:
{
[worldView setMapType:MKMapTypeStandard];
}break;
case 1:
{
[worldView setMapType:MKMapTypeSatellite];
}break;
case 2:
{
[worldView setMapType:MKMapTypeHybrid];
}break;
}
}
Now, whenever the user changes the map type, that value will be written to the NSUser-
Defaults , which will then be saved to disk. When the NSUserDefaults saves its
data to disk, it saves it to the Library/Preferences directory. The name of that file
will be the bundle identifier for your application.
When your application firsts asks for the standardUserDefaults , it will load this
file from disk, and all of the saved preferences will be available to your application. In
WhereamiViewController.m , update the method viewDidLoad to read in this
value and set the map type accordingly.
- (void)viewDidLoad
{
[worldView setShowsUserLocation:YES];
NSInteger mapTypeValue = [[NSUserDefaults standardUserDefaults]
integerForKey:WhereamiMapTypePrefKey];
// Update the UI
[mapTypeControl setSelectedSegmentIndex:mapTypeValue];
// Update the map
[self changeMapType:mapTypeControl];
}
Search WWH ::




Custom Search