我创建了一个自定义注释,右侧有一个按钮,左侧有一个标签。
它显示得很好,标签文本正在完美改变,但由于某种原因,当我单击按钮时它没有反应。我已将 IBAction 连接到它,它应该可以工作。但它只是不调用我的 IBAction。
有谁知道为什么这个按钮忽略了我的触摸?
谢谢,
(MKAnnotationView *)mapView:(MKMapView *)aMapView
viewForAnnotation:(id)ann
{
NSString *identifier = @”myPin”;
MKPinAnnotationView *pin = (MKPinAnnotationView *)
[aMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (pin == nil) {
pin = [[[MKPinAnnotationView alloc] initWithAnnotation:ann
reuseIdentifier:identifier]
autorelease];
} else {
pin.annotation = ann;
}
//---display a disclosure button on the right---
UIButton *myDetailButton =
[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment =
UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment =
UIControlContentHorizontalAlignmentCenter;
[myDetailButton addTarget:self
action:@selector (checkButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
pin.rightCalloutAccessoryView = myDetailButton;
pin.enabled = YES;
pin.animatesDrop=TRUE;
pin.canShowCallout=YES;
return pin;
}
-(void) checkButtonTapped:(id) sender
{
//---know which button was clicked;
// useful for multiple pins on the map---
// UIControl *btnClicked = sender;
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@”Your Current Location”
message :location
delegate:self
cancelButtonTitle:@”OK”
otherButtonTitles:nil];
[alert show];
[alert release];
}
我在我的项目中使用了这个代码,它对我来说很好,所以你可以试试这个。