Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 默认情况下显示Pin信息_Objective C_Ios_Mkmapview_Mkpinannotationview - Fatal编程技术网

Objective c 默认情况下显示Pin信息

Objective c 默认情况下显示Pin信息,objective-c,ios,mkmapview,mkpinannotationview,Objective C,Ios,Mkmapview,Mkpinannotationview,我正在使用MKPinAnnotationView注释引脚在MKMapView上工作。在我正在开发的视图中,有一个以大头针为中心的地图。当我调用视图时,pin会下拉,如果我在其上单击,它会显示注释信息(canShowCallout=YES)。如何在打开视图时获取此详图索引?无需在注释接点上单击 谢谢你的阅读 编辑: 我正在使用这个代码 - (void)viewDidLoad { [super viewDidLoad]; AddressAnnotation *annotation

我正在使用
MKPinAnnotationView
注释引脚在
MKMapView
上工作。在我正在开发的视图中,有一个以大头针为中心的地图。当我调用视图时,pin会下拉,如果我在其上单击,它会显示注释信息(
canShowCallout=YES
)。如何在打开视图时获取此详图索引?无需在注释接点上单击

谢谢你的阅读

编辑:

我正在使用这个代码

- (void)viewDidLoad {

    [super viewDidLoad];

    AddressAnnotation *annotation = [[[AddressAnnotation alloc] initWithCoordinate:self.currentAnnotationCoordinate] autorelease];
    [self.mapView addAnnotation:annotation];
    [self zoomCoordinate:self.currentAnnotationCoordinate];
}

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation {

    // If it's the user location, just return nil.
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;
    else { // Handles the other annotations.
        // Try to dequeue an existing pin view first.
        static NSString *AnnotationIdentifier = @"AnnotationIdentifier";
        MKPinAnnotationView *pinView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];

        if (!pinView) {
            // If an existing pin view was not available, creates one.
            MKPinAnnotationView *customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
            customPinView.animatesDrop = YES;
            customPinView.canShowCallout = YES;

            // Adds a detail disclosure button.
            UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
            customPinView.rightCalloutAccessoryView = rightButton;

            return customPinView;
        } else
            pinView.annotation = annotation;
    }

    return nil;
}


- (void)mapViewDidFinishLoadingMap:(MKMapView *)theMapView {

    AddressAnnotation *annotation = [[[AddressAnnotation alloc] initWithCoordinate:self.currentAnnotationCoordinate] autorelease];

    for (id<MKAnnotation> currentAnnotation in mapView.annotations) {       
        if ([currentAnnotation isEqual:annotation]) {
            [mapView selectAnnotation:currentAnnotation animated:FALSE];
        }
    }
}
可能重复:


您想拨打
[mapView selectAnnotation:

抱歉,问题重复。在将注释添加到viewDidLoad方法后,我正在调用selectAnnotation:方法,但我仍然需要在pin上进行clic以显示信息。您是否尝试按照第一个答案的建议从(void)mapViewDidFinishLoadingMap:(MKMapView*)mapView调用selectAnnotation?我最近回答了类似的问题。看看是否对你有用。谢谢,像这样效果很好。唯一的阴影是引脚在触摸地图之前显示信息(我正在设置下拉菜单的动画)。之后如何执行?请使用performSelector:withObject:afterDelay。看。没有办法知道大头针什么时候碰到地图吗?我不知道,除非你自己画动画。
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {

    id<MKAnnotation> myAnnotation = [self.mapView.annotations objectAtIndex:0];
    [self.mapView selectAnnotation:myAnnotation animated:YES];
}