详细信息按钮无法推送信息。推送的页面总是有空标签

发布于 2024-11-17 00:35:09 字数 2495 浏览 0 评论 0原文

您好,请帮助我....

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

- (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; 

}

//

- (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];

}

Hi can some1 plz help me....

The problem is this: Everything seems alright.. i am able to push to another page once i tap on the detailButton. However, the page which i am able to push to is always only a view without any values passed into the labels. All my labels in the view have nothing inside.. Am i doing something wrong or any wrong concept here?

- (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; 

}

//

- (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];

}

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

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

发布评论

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

评论(1

寻找我们的幸福 2024-11-24 00:35:09

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

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

在该委托方法中,您可以使用以下方式访问点击的注释:

MyAnnotation2 *selectedObject = (MyAnnotation2 *)view.annotation;

Don't use your own target/action and tagging for the callout accessory button.

Instead, use the MKMapViewDelegate method calloutAccessoryControlTapped:. Remove the addTarget line and implement the delegate method.

In that delegate method, you can access the annotation tapped using:

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