Jam*_*tan 12 xcode annotations map mapkit ios
我想知道是否有人能告诉我如何在地图注释中添加正确的标注附件.我尝试的一切似乎都没有到达任何地方,所以任何帮助将不胜感激.
编辑
我已经尝试过这行代码,但注释没有任何不同.
- (MKAnnotationView *)mapview:(MKMapView *)sender viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@""];
aView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
aView.canShowCallout = YES;
aView.annotation = annotation;
return aView;
}
Run Code Online (Sandbox Code Playgroud)
小智 34
方法名称错误.它应该是mapView
一个资本V
:
- (MKAnnotationView *)mapView:(MKMapView *)sender
viewForAnnotation:(id <MKAnnotation>)annotation
Run Code Online (Sandbox Code Playgroud)
Objective-C区分大小写.
如果仍未调用该方法,则另一个问题delegate
是未设置地图视图.在代码中,将其设置为self
或在Interface Builder中将委托附加到文件的所有者.
另外,请确保title
在添加注释之前设置注释,否则标注仍然不会显示.
以上更改应修复未出现的配件按钮.
其他一些不相关的建议......
在viewForAnnotation
,你应该通过调用支持注释视图重用dequeueReusableAnnotationViewWithIdentifier
:
- (MKAnnotationView *)mapView:(MKMapView *)sender viewForAnnotation:(id < MKAnnotation >)annotation
{
static NSString *reuseId = @"StandardPin";
MKPinAnnotationView *aView = (MKPinAnnotationView *)[sender
dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (aView == nil)
{
aView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:reuseId] autorelease];
aView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
aView.canShowCallout = YES;
}
aView.annotation = annotation;
return aView;
}
Run Code Online (Sandbox Code Playgroud)
如果您的项目使用ARC,请删除autorelease
.
顺便说一下,要响应附件按钮,请执行calloutAccessoryControlTapped
委托方法:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"accessory button tapped for annotation %@", view.annotation);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13046 次 |
最近记录: |