如何在 iPhone 的地图上添加按钮

发布于 2024-09-11 01:05:00 字数 139 浏览 1 评论 0原文

我正在尝试使用 MKMapView 在我的应用程序中使用界面生成器拉取地图,但由于某种原因它没有显示。另外,我想向此视图添加一些按钮,单击该按钮我可以浏览 iphone 中现有的文件。

请向我提供详细描述,因为我对此不熟悉。

谢谢,

i am trying to pull a map in my applcation with interface builder using MKMapView but for some reason its not showing up. Also i want to add some button to this view by clicking which i can browse a file existing in my iphone.

Please provide me with the detial description as i am new to this.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红焚 2024-09-18 01:05:01

您需要向地图添加注释,然后为其提供自定义视图。

要向地图添加注释,请在您的对象之一中采用 MKAnnotation 协议,并将其坐标属性设置为适当的纬度/经度位置。

接下来,您将使用 MKMapView addAnnotation 将注释添加到地图。

将地图的委托属性设置为您的视图控制器,然后实现 ma​​pView:viewForAnnotation:

当调用此方法时,为您的注释返回 MKAnnotationView。将 MKAnnotationView 的 image 属性设置为您希望注释使用的任何图像(也许是按钮的图像?)。

如果您想知道注释何时被选择,您可以实现ma​​pView:didSelectAnnotationView:

您还可以使用 MKAnnotationView 的 leftCalloutAccessoryViewrightCalloutAccessoryView 属性在注释上设置标注附件按钮。如果您这样做,则可以在用户选择标注按钮时通过实现 ma​​pView:annotationView:calloutAccessoryControlTapped: 进行响应。

You'll want to add an annotation to the map, then provide a custom view for it.

To add an annotation to the map, adopt the MKAnnotation protocol in one of your objects and set its coordinate property to the appropriate lat/lon location.

Next, you'll add the annotation to the map using MKMapView addAnnotation.

Set the map's delegate property to your view controller, then implement mapView:viewForAnnotation:

When this method gets called, return a MKAnnotationView for your annotation. Set the MKAnnotationView's image property to whatever image you want the annotation to use (an image of a button perhaps?).

You can implement mapView:didSelectAnnotationView: if you want to know when the annotation was selected.

You can also set a callout accessory button on the annotation using MKAnnotationView's leftCalloutAccessoryView and rightCalloutAccessoryView properties. If you do this, you can then respond when the user selects the callout button by implementing mapView:annotationView:calloutAccessoryControlTapped:.

悲喜皆因你 2024-09-18 01:05:01
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationViewID = @"annotationViewID";

     annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    }
    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    annotationView.image = [UIImage imageNamed:@"s11.png"];

    annotationView.annotation = annotation;

    [annotationView setEnabled:YES];
    [annotationView setCanShowCallout:YES];

    return annotationView;
}
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationViewID = @"annotationViewID";

     annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    }
    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    annotationView.image = [UIImage imageNamed:@"s11.png"];

    annotationView.annotation = annotation;

    [annotationView setEnabled:YES];
    [annotationView setCanShowCallout:YES];

    return annotationView;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文