我试了很多谷歌,但还没有显示出来.我的代码如下.
- (voID)addAnnotation{ CLLocationCoordinate2D theCoordinate = self.location.coordinate; MapAnnotation *annotation = [[MapAnnotation alloc] initWithCoordinate:theCoordinate]; annotation.Title = @"Pin"; annotation.subTitle = @"More information"; [self.mapVIEw addAnnotation:annotation];}- (MKAnnotationVIEw *)mapVIEw:(MKMapVIEw *)mapVIEw vIEwForAnnotation:(ID<MKAnnotation>)annotation{ if ([annotation isKindOfClass:[MapAnnotation class]]) { static Nsstring *reuseIDentifIEr = @"MyMKPinAnnotationVIEw"; MKPinAnnotationVIEw *annotationVIEw = (MKPinAnnotationVIEw *)[self.mapVIEw dequeueReusableAnnotationVIEwWithIDentifIEr:reuseIDentifIEr]; if (!annotationVIEw) { annotationVIEw = [[MKPinAnnotationVIEw alloc] initWithAnnotation:annotation reuseIDentifIEr:reuseIDentifIEr]; annotationVIEw.pincolor = MKPinAnnotationcolorRed; annotationVIEw.enabled = YES; annotationVIEw.canShowCallout = YES; annotationVIEw.rightCalloutAccessoryVIEw = [UIbutton buttonWithType:UIbuttonTypeDetaildisclosure]; } else { annotationVIEw.annotation = annotation; } } return nil;}
注意标题&可以显示副标题.
提前致谢.
解决方法 查看标题和副标题是注释视图的默认行为.如果你想做任何其他事情(例如rightCalloutAccessorVIEw),你必须确保通过设置MKMapVIEw的委托来调用vIEwForAnnotation,并确保你的vIEwForAnnotation返回你正在创建的annotationVIEw.发生了两个问题之一:
>在所有情况下,您的vIEwForAnnotation都返回nil.确保在创建/修改后返回annotationVIEw.
>如果尚未设置地图视图的委托,则根本不会调用当前的vIEwForAnnotation.
确保已设置委托.您可以以编程方式执行此 *** 作:
self.mapVIEw.delegate = self;
或者您可以在IB中执行此 *** 作(通过选择连接检查器,右侧面板的最右侧选项卡并从控件拖动到代理到场景的状态栏):
如果是这种情况,请在vIEwForAnnotation中放置NSLog语句或断点.如果没有正确设置委托,您可能根本看不到它被调用.
总结以上是内存溢出为你收集整理的iphone-rightCalloutAccessoryView未显示在MKPinAnnotationView上全部内容,希望文章能够帮你解决iphone-rightCalloutAccessoryView未显示在MKPinAnnotationView上所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)