如何在表格视图单元格中传递位置?什么时候选择一个单元格导航到该位置?

问题描述 投票:0回答:0

the problem that i want to passee 4 countries inside a tableview cells, when select a cell goes to it's country label.

我想要什么,当新闻第一单元去布鲁克林,第二个去昆斯..等等

有人可以帮助我吗?

..在一个表格视图单元格中,每个国家都在一个单元格中,当按下单元格时,该单元格会转到它的国家/地区?我该怎么做

我想传递这些位置数据

这是我到目前为止使用的代码。当我选择一个单元格时,它会在所有位置画一条线。

和委托函数

var countryArray = ["Brooklyn", "Queens", "Manhattan", "The Bronx"]
let coordinates = [ (CLLocationCoordinate2D(latitude: 40.6782, longitude: 73.9442)), (CLLocationCoordinate2D(latitude: 40.7282, longitude: 73.7949)), (CLLocationCoordinate2D(latitude: 40.7831, longitude: 73.9712)), (CLLocationCoordinate2D(latitude: 40.8448, longitude: 73.8648)) ]


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return countryArray.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let locationCell = tableView.dequeueReusableCell(withIdentifier: LocationTableViewCell.locationCellIdentifier, for: indexPath) as! LocationTableViewCell locationCell.countryLable.text = countryArray[indexPath.row] // getting the location based on the country name LocationManger.sharedLocationManager.findLocations(with: countryArray, coordinates: coordinates) { location in self.locationArray = location print("the current location is(location)") } // hide the car cell separator locationCell.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: UIScreen.main.bounds.width) // remove the animation when tapping the cell locationCell.selectionStyle = .none return locationCell }
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    currentLocationTableView.deselectRow(at: indexPath, animated: false)
    // notify map controller to show pin at selected place
    print(locationArray.count)
    print(coordinates)
    let location = locationArray[indexPath.row].coordinates
    self.delegate?.SearchLocationController(self, didSelectLocationWith: location)
}
}
extension SearchLocationController: MKMapViewDelegate { func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { guard !(annotation is MKUserLocation) else { return nil } // set a custom pin var annotaionView = map.dequeueReusableAnnotationView(withIdentifier: "custom") if annotaionView == nil { // create the view annotaionView = MKAnnotationView(annotation: annotation, reuseIdentifier: "custom") // taping in the point annotaionView?.canShowCallout = true annotaionView?.image = UIImage(named: "blueLocation") }
else { annotaionView?.annotation = annotation } return annotaionView
swift location tableview mapkit
© www.soinside.com 2019 - 2024. All rights reserved.