別の ViewController から mapType を変更しようとしていますが、HybridType しか表示されません。セグメント化されたコントロールのボタンが押されても、他の mapType は変更されません。私は何を間違っていますか?前もって感謝します..
-(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");
}
}
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];
そして私の他の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];
}
}