我正在尝试制作一个在地图上放置各种图钉的应用程序。
当我触摸一个大头针时,标准气泡会弹出一个披露按钮。当我单击我的公开按钮时,我希望它打开一个新的 ViewController 以便我可以显示更多信息。
问题是每次我运行应用程序时,它都会崩溃,并且在输出中给我一个错误。
我该如何解决这个问题?
输出中的错误是:
2013-06-29 16:51:33.575 ...[2723:13d03]-[FirstViewController ...Clicked:]:无法识别的选择器发送到实例 0x867d0d0 2013-06-29 16:51:33.576 lam[2723:13d03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FirstViewController ...Clicked:]: unrecognized selector sent to instance 0x867d0d0' * First throw call stack: (0x1d8d012 0x11cae7e 0x1e184bd 0x1d7cbbc 0x1d7c94e 0x11de705 0x182c0 0x18258 0xd9021 0xd957f 0xd86e8 0x47cef 0x47f02 0x25d4a 0x17698 0x1ce8df9 0x1ce8ad0 0x1d02bf5 0x1d02962 0x1d33bb6 0x1d32f44 0x1d32e1b 0x1ce77e3 0x1ce7668 0x14ffc 调用)抛出异常 0x1e12 0x1c++a 4
我的 FirstViewController.m 中的代码是:
[...]
[...]
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
MyPin.pinColor = MKPinAnnotationColorPurple;
UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
if ([[annotation title] isEqualToString:@"..."]) {
[advertButton addTarget:self action:@selector(...Clicked:) forControlEvents:UIControlEventTouchUpInside];
}
if ([[annotation title] isEqualToString:@"..."]) {
[advertButton addTarget:self action:@selector(...Clicked:) forControlEvents:UIControlEventTouchUpInside];
}
MyPin.rightCalloutAccessoryView = advertButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop=TRUE;
MyPin.canShowCallout = YES;
return MyPin;
}
- (void)mapView:(MKMapView *)mapView MyPin:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// Go to edit view
UIViewController *detailViewController = [[UIViewController alloc] initWithNibName:@"...Controller" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
//-(void) ...Clicked:(id)sender {
// NSLog(@"... Clicked");
//}
-(void) ...:(id)sender {
NSLog(@"...");
}
-(IBAction)findmylocation:(id)sender {
mapView.showsUserLocation = YES;
mapView.delegate = self;
[mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
}
导致错误的原因是:
- (void)mapView:(MKMapView *)mapView MyPin:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// Go to edit view
UIViewController *detailViewController = [[UIViewController alloc] initWithNibName:@"..." bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
编辑 2:我已经删除了 advertButton addTarget 行,但是现在我在运行模拟器时没有披露按钮......我删除的内容是否正确?
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
MyPin.pinColor = MKPinAnnotationColorPurple;
UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
if ([[annotation title] isEqualToString:@"..."])
if ([[annotation title] isEqualToString:@"..."])