ios - Swift:Objective-C 方法冲突(尝试更改 calloutview 时出错)

标签 ios objective-c swift

我正在尝试更改图钉的标注 View 。我使用包含标签和图像的 .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
    }
}

问题是我得到这个错误:

Objective-C method 'mapView:didSelectAnnotationView:' provided by method 'mapView(:didSelectAnnotationView:)' conflicts with optional requirement method 'mapView(:didSelectAnnotationView:)' in protocol 'MKMapViewDelegate'

找不到解决方案。

我使用这个 Objective-C 库:https://github.com/RVLVR/REVClusterMap 它聚集了注释。

我在这个库的一个文件中找到了这个方法:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    if( [delegate respondsToSelector:@selector(mapView:didSelectAnnotationView:)] )
    {
        [delegate mapView:mapView didSelectAnnotationView:view];
    }
}

但即使我评论它,错误仍然不会消失:(

我做错了什么?

谢谢!

最佳答案

MKMapViewDelegate 的委托(delegate)方法didSelectAnnotationView 没有返回值。改变这一行

func mapView(mapView: MKMapView!, didSelectAnnotationView annotation: MKAnnotationView!) -> UIView!

func mapView(mapView: MKMapView!, didSelectAnnotationView annotation: MKAnnotationView!)

关于ios - Swift:Objective-C 方法冲突(尝试更改 calloutview 时出错),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30164728/

相关文章:

ios - 在 Swift 中每次点击都执行一些操作

xcode - 如何在 Xcode 中将 NSClickGestureRecogniser 与 Swift 一起使用?

ios - 如何更新一个 xcode 实例?

objective-c - Objective-C 接口(interface)的前向声明

ios - 多久检查一次 APNS 反馈?

ios - 如何将标识符添加到 unwind segue - Swift

ios - 我无法再在我的设备上测试我的应用程序

html - 在 Swift 4 中将属性文本转换为 HTML

ios - 如果来自另一个应用程序的音乐正在 spritekit 中播放,如何使 AVAudioPlayer 静音

iphone - 无法将头文件链接到 xcode 项目