0

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

これは地図と注釈です。タブを表示すると、開示ボタン画像 2 が表示され、選択した注釈の説明が選択されます。

ここに画像の説明を入力

4

3 に答える 3

1

以下のコードを使用して、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];
}
于 2012-09-11T12:40:43.780 に答える
0

次のデリゲート メソッドを使用します。

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
      AnnotationView *annotation = (AnnotationView *)mapView.annotation;
      NSInteger *yourIndex = annotation.myindex;
}

ナビゲーションコントローラーをプッシュします

于 2012-09-11T12:20:59.003 に答える
0

デリゲート メソッドdidSelectAnnotationView:を使用して、detalViewController をナビゲーション コントローラーにプッシュします。

これは役に立ちます。

于 2012-09-11T12:09:31.890 に答える