我正试图改变别针的标注视图。我使用一个包含标签和图像的.xib,它应该在用户点击注释时出现。
我使用以下代码:
func mapView(mapView: MKMapView!, didSelectAnnotationView annotation: MKAnnotationView!) -> UIView!
{
println("delegate")
let pin = annotation as! CustomPointAnnotation
if let infoView = UIView.viewFromNibName("AnnInfoView") as? AnnInfoView {
infoView.nameLabel.text = pin.title
if let photo = pin.imageName {
infoView.placePhoto.image = UIImage(named: photo)
} else {
infoView.placePhoto.image = UIImage(named: "generic")
}
return infoView
} else {
return nil
}
}问题是,我得到了这个错误:
目标-C方法'mapView:didSelectAnnotationView:‘by 'mapView(:didSelectAnnotationView:)’与协议'MKMapViewDelegate‘中的可选需求方法'mapView(:didSelectAnnotationView:)’冲突。
却找不到解决办法。
我使用了一个目标-C库:https://github.com/RVLVR/REVClusterMap,它对注释进行集群。
我在这个库的一个文件中发现了这种方法:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
if( [delegate respondsToSelector:@selector(mapView:didSelectAnnotationView:)] )
{
[delegate mapView:mapView didSelectAnnotationView:view];
}
}但是,即使我评论,错误仍然不会消失:
我做错了什么?
谢谢!
发布于 2015-05-11 10:21:02
委托方法didSelectAnnotationView of MKMapViewDelegate没有返回值。更改这一行
func mapView(mapView: MKMapView!, didSelectAnnotationView annotation: MKAnnotationView!) -> UIView!至
func mapView(mapView: MKMapView!, didSelectAnnotationView annotation: MKAnnotationView!)https://stackoverflow.com/questions/30164728
复制相似问题