Content Scroll to Row at Index Path beyond bonds?

Multi tool use
Content Scroll to Row at Index Path beyond bonds?
So I was able to have the annotation's callout animate when the selected table cell was selected like so. Quite simple due to the indexPath.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let indexPath = indexPath.row
myMap.selectAnnotation(pinArray[indexPath] , animated: true)
}
However, I do not understand how to achieve this when I select the annotation and want the table cell to light up. I've been attempting to set a var to indexPath but because the annotation has no subscript, I am unable to perform this. Therefore, how would I be able to accomplish the annotation to selected cell logic?
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
//Magic
}
Update -
currently the code I have to highlight the table cell correlated to the map annotation is this.
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
let index = pinArray.index(of: view.annotation as! AnnotationPin)
let indexPath = IndexPath(row: index!, section: 0)
myTable.selectRow(at: indexPath, animated: true, scrollPosition: .top)
}
Unfortunately, I receive this error message when I click on a map annotation.
-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:usingPresentationValues:]: row (72) beyond bounds (17) for section (0).
I don't understand as the array only has 12 records tops, so I completely don't understand how a row above 15 can be mentioned to be beyond bounds.
pinArray
MKannotations used in the map
– Jonathan Gardocki
Jun 30 at 17:08
1 Answer
1
IndexPath
e.g.
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
// Get index of pinArray
let index = pinArray.index{$0 === view.annotation}
// Make IndexPath
let indexPath = IndexPath(row: index, section: 0)
// Select row of TableView
tableView.selectRow(at: indexpath, animated: true, scrollPosition: .bottom)
}
Almost perfect. However, depending on which annotation I select, the program will crash and xcode will say that the selected index is beyond bonds. which I don't understand.
– Jonathan Gardocki
Jun 30 at 20:01
You should check if 'IndexPath' exists. See also stackoverflow.com/a/43618106/1155354
– Kosuke Ogawa
Jul 1 at 0:21
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What kind of elements are inside
pinArray
?– Kamran
Jun 30 at 9:44