首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >detailButton无法推送信息。推送的页面总是有空标签

detailButton无法推送信息。推送的页面总是有空标签
EN

Stack Overflow用户
提问于 2011-06-27 01:04:10
回答 1查看 131关注 0票数 0

嗨,some1能帮我吗……

问题是:一切似乎都很好..一旦我点击detailButton,我就可以推送到另一个页面。但是,我能够推送到的页面始终只是一个视图,没有任何值传递到标签中。视图中的所有标签都没有任何内容..我是不是做错了什么,或者有什么错误的概念?

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

    BOOL isRed = NO;
    //BOOL isPurple = YES;

    if([annotation isKindOfClass:[MyAnnotation2 class]])
        isRed = YES;



    MKPinAnnotationView *pinView = nil;



    if(isRed) {
        static NSString *redPin = @"redPin";
        pinView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:redPin];
        if (!pinView) {
            pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:redPin] autorelease];
            pinView.pinColor = MKPinAnnotationColorRed;
            pinView.animatesDrop = YES;
            pinView.canShowCallout = YES;

            UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


            pinView.rightCalloutAccessoryView = detailButton;

        }

        else{
            pinView.annotation = annotation;
        }    
    }
    else {
        static NSString *greenPin = @"greenPin";
        pinView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:greenPin];
        if (!pinView) {
            pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:greenPin] autorelease];
            pinView.pinColor = MKPinAnnotationColorGreen;
            pinView.animatesDrop = NO;
            pinView.canShowCallout = YES;
            UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


            pinView.rightCalloutAccessoryView = detailButton;

        }

    }  
    return pinView; 

}

//

代码语言:javascript
复制
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"calloutAccessoryControlTapped");

if (self.patientDetailsViewController == nil) {
    self.patientDetailsViewController = [[[PatientDetailsViewController alloc] initWithNibName:@"PatientDetailsViewController" bundle:nil] autorelease];        
} 

MyAnnotation2 *selectedObject = (MyAnnotation2 *)view.annotation;
_patientDetailsViewController.nric = selectedObject.title;
NSLog(@"%@",_patientDetailsViewController.nric);
[self.navigationController pushViewController:_patientDetailsViewController animated:YES];

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-27 01:20:51

不要对callout附件按钮使用自己的目标/操作和标记。

相反,请使用MKMapViewDelegate方法calloutAccessoryControlTapped:。删除addTarget行并实现委托方法。

在委托方法中,您可以使用以下命令访问点击的批注:

代码语言:javascript
复制
MyAnnotation2 *selectedObject = (MyAnnotation2 *)view.annotation;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6485380

复制
相关文章

相似问题

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