[英]ViewController does not conform to protocol GMSAutoCompleteViewControllerDelegate in Swift
我收到错误消息:“ ViewController”不符合以下代码中的协议“ GMSAutoCompleteViewControllerDelegate”。
class MapViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate, GMSAutocompleteViewControllerDelegate {
...
@IBAction func autocompleteClicked(sender: AnyObject) {
let autoCompletController = GMSAutocompleteViewController()
autoCompletController.delegate = self
self.presentViewController(autoCompletController, animated: true, completion: nil)
}
//Handle user's selection
func viewController(viewController: GMSAutocompleteViewController!, didAutocompleteWithPlace place: GMSPlace!) {
//let placeName = place.name
//let placeAddress = place.formattedAddress
//let placeAttributions = place.attributions
let placeCoordinate = place.coordinate
mapView.camera = GMSCameraPosition(target: placeCoordinate, zoom: 15, bearing: 0, viewingAngle: 0)
}
func viewController(viewController: GMSAutocompleteViewController!, didAutocompleteWithError error: NSError!) {
// TODO: handle the error.
print("Error: ", error.description)
}
func wasCancelled(viewController: GMSAutocompleteViewController!) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
解决办法是什么? 谢谢
我刚刚在Swift 3中收到此错误,并将其更改为以下内容对我有用:
func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Swift.Error) {
// TODO: handle the error.
print("Error: \(error.localizedDescription)")
}
好像您输错了必需的功能之一。 didAutoCompleteWithError
func viewController(viewController: GMSAutocompleteViewController!, didFailAutocompleteWithError error: NSError!) {
// TODO: handle the error.
print("Error: ", error.description)
}
编辑: 有关GoogleDevelopers文档中提供的GMSAutocompleteViewControllerDelegate协议参考的信息。
Google在其文档中提供的示例之一是GMSAutocompleteViewControllerDelegate的错误表示。 看来该示例是从Objective-C等效项的纯翻译,因此对所需的委托函数给出了错误的描述。
将示例与此处的实际文档进行比较。 取通知didAutocompleteWithError
在实施例和对didFailAutocompleteWithError
在协议参考。
如果我错了纠正我。
您可能缺少GMSMapViewDelegate
协议中的必需功能。 Ctrl +单击GMSMapViewDelegate
并查看列出的功能:您是否实现了未列出为@optional
所有功能? 如果您还没有,Swift将不会编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.