我在swift中构建了一个应用程序,该应用程序在同一页面上具有集合视图和地图视图。用户可以滚动浏览收藏视图以查看优惠(这是应用的目的),并且地图视图中填充了注释引脚,用于在地图上显示优惠的实际位置。需要帮助将mapKit注释链接到Swift中的CollectionView
我的问题是,我发现很难收集观察室链接到正确的注释。
我的注释添加到地图如下:
for location in self.queryDataMapAnnotations {
let annotation = MKPointAnnotation()
annotation.title = location["title"] as? String
annotation.subtitle = location["distance"] as? String
annotation.coordinate = CLLocationCoordinate2D(latitude: location["latitude"] as! Double, longitude: location["longitude"] as! Double)
self.mapView.addAnnotation(annotation)
}
我则可以通过收集的滚动视图细胞
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// get a reference to our storyboard cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MyCollectionViewCell
// Connect cell to the linked annotation
// ** This links to a random annotation, but not the correct one - need help on this please **
self.mapView.selectAnnotation(self.mapView.annotations[row], animated: true)
}
如果任何人能帮助我如何收集链接查看正确的地图注释,我会是最有帮助的。我只知道很快(一点点),所以会欣赏那种语言的帮助。由于
你的目的,突出标注时收集细胞是** **螺孔?因为目前您在错误的集合视图dataSource方法中调用'selectAnnotation()'。 – nshuman
不,用途是在用户滚动浏览集合视图时选择注释。因此,当用户滚动到第1个集合视图单元格时,会选中相应的注释并显示标题和副标题。然后,当用户滚动到第二个单元格,第三个等时,这继续下去。 –