无法在viewDidLoad

时间:2018-01-17 13:58:44

标签: ios swift swift4

我在控制器中创建了这个功能

func addMarker(place:EClass) {

    guard let coordinates = place.location  else {
        return
    }

    self.destination = coordinates
    // clear current marker
    marker.map = nil

    marker.position = coordinates
    marker.title = place.name
    marker.map = mapView
    mapView.selectedMarker = marker

    }
}

现在我试图在我的viewDidLoad中调用它,因为我想在mapView中添加一些标记

override func viewDidLoad() {
        super.viewDidLoad()
        print(categories as Any)

        guard let currentUser = Auth.auth().currentUser else {
            return
        }



        tableView.dataSource = self
        tableView.delegate = self

        dateFormatter.timeZone = TimeZone.current
        dateFormatter.dateFormat = "hh:mm"
        print(dateFormatter.string(from: NSDate() as Date))


         mapView.isMyLocationEnabled = true
         locationManager?.startUpdatingLocation()


         //HERE 
         let srt = sortedArray
         for category in categories! {
            addMarker(place: srt)
        }



}

但我收到错误"使用未解析的标识符' addMarker'" ,为什么?我该如何解决?

1 个答案:

答案 0 :(得分:1)

您的addMarker有一个额外的括号。

 func addMarker(place:EClass) {

    guard let coordinates = place.location  else {
        return
    }

    self.destination = coordinates
    // clear current marker
    marker.map = nil

    marker.position = coordinates
    marker.title = place.name
    marker.map = mapView
    mapView.selectedMarker = marker

 }