私は地図を持っていて、複数の注釈がドロップされています。注釈を選択し、開示ボタンをタップすると、テーブル ビューを含む新しいビュー (DetailViewController) が表示されます。私が欲しいのは、DetailViewController が開いたときに、選択した注釈の説明が直接選択されることです。


私は地図を持っていて、複数の注釈がドロップされています。注釈を選択し、開示ボタンをタップすると、テーブル ビューを含む新しいビュー (DetailViewController) が表示されます。私が欲しいのは、DetailViewController が開いたときに、選択した注釈の説明が直接選択されることです。


以下のコードを使用して、MKMapViewでMKAnnotationが選択されていることを検出できます。
@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;
}
次に、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];
}
次のビューで、このコード行を追加します
NSIndexPath *index =[NSIndexPath indexPathWithIndex:[name1Str intValue]];
[tableView selectRowAtIndexPath:index animated:NO scrollPosition:UITableViewScrollPositionMiddle];
私の場合、以下のコードを使用してリロードしました。これも試すことができます
- (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];
}
次のデリゲート メソッドを使用します。
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
      AnnotationView *annotation = (AnnotationView *)mapView.annotation;
      NSInteger *yourIndex = annotation.myindex;
}
ナビゲーションコントローラーをプッシュします
デリゲート メソッドdidSelectAnnotationView:を使用して、detalViewController をナビゲーション コントローラーにプッシュします。
これは役に立ちます。