gpt4 book ai didi

ios - NSNotificationCenter 和 mapType

转载 作者:行者123 更新时间:2023-11-28 22:47:45 24 4
gpt4 key购买 nike

我正在尝试从另一个 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];
}
}

最佳答案

一切似乎都很好。检查分段控件中的所有 iboutlet 和日志在这种情况下可能更有帮助。另一件事你应该使用 break;在开关案例中声明,否则它会继续执行下面的代码,所以当你想发送 TestNotification 时,它也会发送下面的其他两个通知。

关于ios - NSNotificationCenter 和 mapType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12766954/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com