Я хотел бы показать некоторую информацию в MKAnnotationView, но количество элементов не всегда одинаково, поэтому я хотел бы сделать непрокручиваемый UITableView в этом MKAnnotationView. У меня не получилось сделать это должным образом. Когда аннотация размещена, аннотация не отображается при нажатии на нее.
Изменить с комментарием Йоакима: tableView отображается за пределами AnnotationView и не исчезает при нажатии снаружи.
extension MapViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let reuseIdentifier = "pin"
var pinView = self.mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier) as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
let placesTableView = UITableView(frame: CGRect(x: 0, y: 0, width: 150, height: 200))
placesTableView.delegate = self
placesTableView.dataSource = self
placeData = ["France", "Ile de france", "Paris"]
pinView?.addSubview(placesTableView)
} else {
pinView?.annotation = annotation
}
return pinView
}
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
GlobalVariables.sharedInstance.selectedCountry = mapView.selectedAnnotations[0].title!!
self.tabBarController?.selectedIndex = 0
FIRAnalytics.logEvent(withName: "location_from_map", parameters: [
"location": GlobalVariables.sharedInstance.selectedCountry as NSObject
])
}
}
extension MapViewController: UITableViewDelegate {
}
extension MapViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return placeData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
cell.textLabel?.text = placeData[indexPath.item]
return cell
}
}
PS: представление аннотации видно с другим кодом, который я разместил, поэтому я знаю, что проблема связана с реализацией табличного представления.
UIStackView
:-) - person olejnjak   schedule 04.06.2017