0

別の 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];
}
}
4

2 に答える 2

1

すべて問題ないようです。この場合、セグメント化されたコントロールとログからすべての ioutlets を確認すると、より役立つ可能性があります。ブレークを使用する必要があるもう 1 つのこと。それ以外の場合は、以下のコードを実行し続けるため、TestNotification を送信する場合は、以下の他の 2 つの通知も送信します。

于 2012-10-07T07:52:29.160 に答える
1

switch / caseの「 break 」を見逃しています。

于 2012-10-07T07:55:13.493 に答える