我认为我的代码中有问题,但我找不到它。
我只想点击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
答案 0 :(得分:2)
在addTarget
中,代码表示该按钮应调用方法showDetailView:
:
[detailButton addTarget:self action:@selector(showDetailView:) forControlEvents...
但是没有这样的方法(这就是错误的含义)。
从以下位置更改此方法的名称:
- (IBAction)detailButton:(UIButton *)sender
为:
- (IBAction)showDetailView:(UIButton *)sender