首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >详细信息披露按钮未显示在地图工具包标注中

详细信息披露按钮未显示在地图工具包标注中
EN

Stack Overflow用户
提问于 2012-09-03 19:41:05
回答 2查看 1.5K关注 0票数 2

我不确定为什么详细信息披露按钮没有出现在mapkit标注中。下面是我的代码:

我确保在.h文件中包含了以下方法。详图索引工作,并在地图加载后立即显示。我还确保在Xib文件中挂接了委托。

代码语言:javascript
复制
   - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *mapPin = nil;
    if(annotation != map.userLocation) 
    {
        static NSString *defaultPinID = @"defaultPin";
        mapPin = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if (mapPin == nil )
        {
            mapPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation 
                                                     reuseIdentifier:defaultPinID];
            mapPin.canShowCallout = YES;

            UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            [disclosureButton addTarget:self action:@selector(clDetails:) forControlEvents:UIControlEventTouchUpInside];

            mapPin.rightCalloutAccessoryView = disclosureButton;

        }
        else
            mapPin.annotation = annotation;

    }
    return mapPin;
}




  - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    id<MKAnnotation> myAnnotation = [self.mapView.annotations objectAtIndex:0];
    [self.mapView selectAnnotation:myAnnotation animated:YES];
}

谢谢你的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-03 20:49:34

我在viewDidLoad中有这行代码,它抛弃了MKAnnotation方法。

代码语言:javascript
复制
mapView = [[MKMapView alloc]initWithFrame:self.view.bounds];

:)

票数 1
EN

Stack Overflow用户

发布于 2012-09-03 21:36:00

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

{ //如果是用户位置,则返回nil。if ([annotation isKindOfClass:MKUserLocation class])返回nil;

代码语言:javascript
复制
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
                                 initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
pinView.draggable = NO;
pinView.annotation = annotation;
pinView.draggable = YES;
pinView.enabled = YES;
pinView.exclusiveTouch = YES;
pinView.highlighted = YES;
pinView.multipleTouchEnabled = YES;
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.userInteractionEnabled = YES;

//button on the right for popup for pins
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
                action:@selector(showDetails:)
      forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;


 //Create and add the right button to the callout
 rightCalloutButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[pinView setRightCalloutAccessoryView:rightButton];

    [self updateAnnotation];

    [self crawlViews];

//zoom button on the left of popup for pins
UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[leftButton setTitle:annotation.title forState:UIControlStateNormal];
[leftButton addTarget:self 
               action:@selector(zoomToLocation:) forControlEvents:UIControlEventTouchUpInside];
pinView.leftCalloutAccessoryView = leftButton;

UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
[profileIconView release];

return pinView;

}

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

https://stackoverflow.com/questions/12247141

复制
相关文章

相似问题

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