I am trying to change the mapType from another ViewController but It only displays the HybridType. Any other mapType is not changing whatever the button on my segmented control is pressed. What am I doing wrong? Thank you in advance..
-(void) receiveTestNotification:(NSNotification *) notification{
_mapView.delegate = self;
if ([[notification name] isEqualToString:@"TestNotification"]) {
_mapView.mapType = MKMapTypeStandard;
NSLog(@"Successfully changed maptype");
}
if ([[notification name] isEqualToString:@"TestNotification2"]) {
_mapView.mapType = MKMapTypeSatellite;
NSLog(@"Successfully changed maptype");
}
if ([[notification name] isEqualToString:@"TestNotification3"]) {
_mapView.mapType = MKMapTypeHybrid;
NSLog(@"Successfully changed maptype");
}
}
in ViewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveTestNotification:) name:@"TestNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveTestNotification:) name:@"TestNotification2" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveTestNotification:) name:@"TestNotification3" object:nil];
and in my other viewController:
- (IBAction)segmentedControl:(id)sender {
switch (((UISegmentedControl *) sender).selectedSegmentIndex) {
case 0:
[[NSNotificationCenter defaultCenter] postNotificationName:@"TestNotification" object:self];
[self dismissModalViewControllerAnimated:YES];
case 1:
[[NSNotificationCenter defaultCenter] postNotificationName:@"TestNotification2" object:self];
[self dismissModalViewControllerAnimated:YES];
case 2:
[[NSNotificationCenter defaultCenter] postNotificationName:@"TestNotification3" object:self];
[self dismissModalViewControllerAnimated:YES];
}
}