我创建了一个自定义按钮,为什么我需要在@selector 中作为参数传递。自定义按钮是 annotationView 的一部分。在 CustomButton 中,我将其作为属性 UIButtonType,但在输出中什么也没有出现。输出是一个没有任何内容的按钮,当我想要打开视图控制器时,当我在注释内部进行修饰时会消失。
这是 CustomButton.h 中的代码
@interface CustomButton : UIButton{
}
@property (nonatomic, strong)NSString * name;
@property (nonatomic, assign)UIButtonType typeButton;
@end
在 CustomButton.m
@implementation CustomButton.h
@synthesize name;
@synthesize buttonType;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.typeButton = UIButtonTypeInfoLight;
}
return self;
}
在 MapViewController.m
-(void)loadDetailListViewController: (CustomButton *)aName{
//I want to open a viewController
//.......
}
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id
<MKAnnotation>)annotation
{
//.......
MKPinAnnotationView *annotationView = (MKPinAnnotationView*) [mapView
dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier];
//.........
CustomButton *rightButton = [CustomButton buttonWithType:UIButtonTypeCustom];
[rightButton setName:[NSString stringWithFormat:@"%@", self.nameTable]];
[rightButton addTarget:self action: @selector(loadDetailListViewController:)
forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
annotationView.canShowCallout = YES;
annotationView.draggable = YES;
return annotationView;
}
为什么当我触摸里面的注解消失了?