0

我认为我的代码有问题,但我找不到。

我想通过单击leftCalloutAccessoryView按钮来切换视图,但我总是收到相同的错误:

NSInvalidArgumentException', reason: '
-[ThirdViewController showDetailView:]: unrecognized selector sent to instance

这是我的代码:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]])
    {
        return nil;
    }
    else
    {
        MKPinAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"loc"];
        annotationView.canShowCallout = YES;
        UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

        [detailButton addTarget:self action:@selector(showDetailView:) forControlEvents:UIControlEventTouchUpInside];
        annotationView.rightCalloutAccessoryView=detailButton;
        annotationView.enabled = YES;

        UIImage *image = [UIImage imageNamed:@"logo.jpeg"];
        UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
        annotationView.leftCalloutAccessoryView = imgView;
        annotationView.image = [UIImage imageNamed:@"pin.png"];
        return annotationView;
    }
}
- (IBAction)detailButton:(UIButton *)sender
{
    ThirdViewController *infoView = [[ThirdViewController alloc] init];
    [self.navigationController pushViewController:infoView animated:YES];
    NSLog(@"pushed Button!!!!!!");

}

我的故事板的小截图:

在此处输入图像描述

感谢您的帮助!

最好的问候 CTS

4

1 回答 1

2

在中addTarget,代码说按钮应该调用方法showDetailView:

[detailButton addTarget:self action:@selector(showDetailView:) forControlEvents...

但是没有这样的方法(这就是错误的意思)。


更改此方法的名称:

- (IBAction)detailButton:(UIButton *)sender

到:

- (IBAction)showDetailView:(UIButton *)sender
于 2013-02-07T17:13:33.020 回答