首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法在MKMapView上的多个MKPointAnnotations上打开多个callouts?

有没有办法在MKMapView上的多个MKPointAnnotations上打开多个callouts?
EN

Stack Overflow用户
提问于 2012-05-06 10:58:44
回答 2查看 1.6K关注 0票数 0

我想知道是否有可能做到这一点,或者如果不是,有什么替代方案?我需要一些需要在地图上显示的信息,但我在这方面遇到了问题...MKPointAnnotation提供了一个很好的界面,但是我还没能一次打开一个以上的标注。谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-05-06 21:24:43

我找到了解决方案:

您需要先阅读以下内容:

http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html

这里有一个例子:

http://shawnsbits.com/blog/2011/04/12/custom-map-pins-for-mapkit/

关键是在viewDidLoad中加载带有自定义图像的注释数组,然后在mapView:viewForAnnotation:创建一个新的MKAnnotationView,并通过将注释转换为传递给它的自定义注释将图像加载到其中。

我希望这能帮到你。如果它看起来有点混乱,很抱歉!

票数 0
EN

Stack Overflow用户

发布于 2012-05-06 11:15:41

在注释中添加按钮和为button.You设置标签也可以与自定义注释一起使用,但在底线方法与below.You相同,需要为打开多个注释设置标识符(标签)。

代码语言:javascript
复制
  - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

     {

         MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.map      dequeueReusableAnnotationViewWithIdentifier: @"restMap"];
         if (pin == nil) {
            pin = [[[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"restMap"] autorelease];
          }

          else {
              pin.annotation = annotation;
               }

          // add cutom button by following way.
          UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeCustombutton];


          // you just need to find an integer value that matches your object in some way:
          // its index in your array of MKAnnotation items, or an id of some sort, etc

          NSInteger annotationValue = [self.annotations indexOfObject:annotation];

          // set the tag property of the button to the index
          detailButton.tag = annotationValue;

          pin.rightCalloutAccessoryView = detailButton;
          return pin;
    }




     -(IBAction)showDetailofannotation:(UIView*)sender {
       // get the tag value from the sender
        NSInteger annotationtag = sender.tag;
        MyAnnotationObject *selectedObject = [self.annotations objectAtIndex:annotationtag ];

   // now you know which detail view you want to show; the code that follows

        YourDetailViewController *detailView = [[YourDetailViewController alloc] initWithNibName:@"YourDetailViewController ", NSBundle:nil];
detailView.detailObject = selectedObject;

       [[self navigationController] pushViewController:detailView animated:YES];
        [detailView release];`
     }

希望,这会帮助你..

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10467737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档