gpt4 book ai didi

ios - 新的 PList 检索代码可防止调用 MKMapView 委托(delegate)方法 (iOS)

转载 作者:行者123 更新时间:2023-11-29 04:54:47 26 4
gpt4 key购买 nike

我添加了一个 plist 数据库来存储 MKMapView 中注释的信息。一旦我实现了获取信息的代码,我的委托(delegate)方法就不再被调用。

我添加的代码是:

- (void)viewDidLoad
{
NSMutableArray *annotations = [[NSMutableArray alloc]init];
NSString *path = [[NSBundle mainBundle] pathForResource:@"MillersStores" ofType:@"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
NSArray *anns = [dict objectForKey:@"Root"];
for(int i = 0; i < [anns count]; i++) {
float realLatitude = [[[anns objectAtIndex:i] objectForKey:@"Latitude"] floatValue];
float realLongitude = [[[anns objectAtIndex:i] objectForKey:@"Longitude"] floatValue];

MillersLocations *myAnnotation = [[MillersLocations alloc] init];
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = realLatitude;
theCoordinate.longitude = realLongitude;
myAnnotation.coordinate = theCoordinate;
myAnnotation.title = [[anns objectAtIndex:i] objectForKey:@"Title"];
myAnnotation.subtitle = [[anns objectAtIndex:i] objectForKey:@"Address"];
[mapView addAnnotation:myAnnotation];
[annotations addObject:myAnnotation];
[myAnnotation release];
}
}

这是不再被调用的委托(delegate)方法之一:

- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;

MKPinAnnotationView *pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;

UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MillersAnnotation.png"]];
pinView.leftCalloutAccessoryView = leftIconView;

UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = rightButton;
return pinView;
}

我还有另一个委托(delegate)方法,它也可以放大也没有被调用的用户位置,以及不再被调用的 calloutAccessoryControlTapped 方法。

我知道它与新代码有关,但我对如何调试它感到困惑,因为它没有给我错误,而且我无法记录它,因为甚至没有调用整个方法。当我摆脱新代码时,旧代码可以正常工作...新代码中的什么内容否定了旧代码?

最佳答案

听起来 map View 的 delegate 属性未设置。

旧代码是否包含此行:

mapView.delegate = self;

将其添加到 viewDidLoad 中,或者在 IB 中,将 map View 的 delegate 导出连接到文件的所有者。

关于ios - 新的 PList 检索代码可防止调用 MKMapView 委托(delegate)方法 (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8216214/

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