我想從另一個ViewController更改mapType,但它只顯示HybridType。任何其他mapType都不會改變我的分段控件上的按鈕被按下。我究竟做錯了什麼?預先感謝您..NSNotificationCenter和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];
}
}