我正在尝试从另一个 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];
在我的另一个视图控制器中:
- (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];
}
}