0

我对数据传递知之甚少,需要帮助了解如何传递已经填充了 mapview 的 LocalSearchResponse,然后使用 UIButton 连接到 tableview 以列出这些引脚注释。

matchingItems.removeAll()
    let request = MKLocalSearchRequest()
    request.naturalLanguageQuery = shopType
    request.region = mapView.region

    let search = MKLocalSearch(request: request)

    search.start(completionHandler: {(response, error) in

        if error != nil {
            print("Error occured in search: \(error!.localizedDescription)")
        } else if response!.mapItems.count == 0 {
            print("No matches found")
        } else {
            print("Matches found")

            for item in response!.mapItems {
                print("Name = \(String(describing: item.name))")
                print("Phone = \(String(describing: item.phoneNumber))")

                self.matchingItems.append(item as MKMapItem)
                print("Matching items = \(self.matchingItems.count)")

                let annotation = MKPointAnnotation()
                annotation.coordinate = item.placemark.coordinate
                annotation.title = item.name
                self.mapView.addAnnotation(annotation)

                self.listedButton.isEnabled = true
            }
        }
    })

我想在表格视图中列出使用名称和电话搜索的地点。

4

0 回答 0