You can use the below code for detecting when MKAnnotation is selected in MKMapView
@interface ClassVC ()
{
int notationTag;
}
- (void)viewDidLoad
{
notationTag = 0; //initialisation of variable
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// If it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// Handle any custom annotations.
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
// Try to dequeue an existing pin view first.
MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
if (!pinView)
{
// If an existing pin view was not available, create one.
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:@"mallicon.png"];
pinView.calloutOffset = CGPointMake(0, 32);
//pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.tag = notationTag;
} else {
pinView.annotation = annotation;
}
notationTag++;
return pinView;
}
return nil;
}
then in calloutAccessoryControlTapped.,
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
ContactDetails *contact=[[ContactDetails alloc] initWithNibName:@"ContactDetails" bundle:nil];
contact.name1Str = [NSString stringWithFormat:@"%d",view.tag];
}
in the next view add this line of code
NSIndexPath *index =[NSIndexPath indexPathWithIndex:[name1Str intValue]];
[tableView selectRowAtIndexPath:index animated:NO scrollPosition:UITableViewScrollPositionMiddle];
In my case I used below code to reload you can try that too
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
self.mapView.centerCoordinate = view.annotation.coordinate;
NSLog(@"======Tag====%ld", (long)view.tag);
NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:[view tag] inSection:0];
[self.collectionView scrollToItemAtIndexPath:rowToReload atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
}