gpt4 book ai didi

objective-c - 未调用 ViewForAnnotation

转载 作者:太空狗 更新时间:2023-10-30 03:13:53 27 4
gpt4 key购买 nike

我正在尝试制作一张 map ,在那里我可以看到我当前的位置,并看到这条街叫什么。

到目前为止,我可以在我的 map 上放置图钉,但出于某种原因,我没有收到标注。并且我在我的 viewForAnnotation 方法中放置了一个 NSLog,但它没有被调用,所以我无法测试它。

谁能帮帮我?

-(void)lat:(float)lat lon:(float)lon
{
CLLocationCoordinate2D location;
location.latitude = lat;
location.longitude = lon;
NSLog(@"Latitude: %f, Longitude: %f",location.latitude, location.longitude);
//One location is obtained.. just zoom to that location

MKCoordinateRegion region;
region.center=location;
//Set Zoom level using Span
MKCoordinateSpan span;
span.latitudeDelta=.005f;
span.longitudeDelta=.005f;
region.span=span;
[map setRegion:region animated:TRUE];

//MKReverseGeocoder *geocoder=[[MKReverseGeocoder alloc] initWithCoordinate:location];
//geocoder.delegate=self;
//[geocoder start];
if (cPlacemark != nil) {
[map removeAnnotation:cPlacemark];
}
cPlacemark=[[CustomPlacemark alloc] initWithCoordinate:location];
cPlacemark.title = mPlacemark.thoroughfare;
cPlacemark.subtitle = mPlacemark.locality;
[map addAnnotation:cPlacemark];
[cPlacemark release];

[mLocationManager stopUpdatingLocation];
}

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

// try to dequeue an existing pin view first
if ([annotation isKindOfClass:[CustomPlacemark class]]){
MKPinAnnotationView *pinView=(MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:@"customIdentifier"];

if (!pinView)
{
// if an existing pin view was not available, create one
MKPinAnnotationView* cPinAnnoView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:@"customIdentifier"] autorelease];
cPinAnnoView.pinColor = MKPinAnnotationColorPurple;
cPinAnnoView.animatesDrop = YES;
cPinAnnoView.canShowCallout = YES;
// Add button
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[leftButton addTarget:self action:@selector(annotationViewClick:) forControlEvents:UIControlEventTouchUpInside];
cPinAnnoView.leftCalloutAccessoryView = leftButton;

} else
{
pinView.annotation = annotation;
}
return pinView;
}
return nil;

现在我已经将我的 viewForAnnotation 定制成这样。但我仍然无法从我的图钉中得到标注,图钉仍然是红色的。但它应该是什么都没有的紫色

最佳答案

我有同样的问题,就是没有将 MapView 委托(delegate)设置为文件所有者。

  1. 打开你的 Nib
  2. 右键单击 map View
  3. 将委托(delegate)拖到文件所有者处

关于objective-c - 未调用 ViewForAnnotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3821515/

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