我創建了一個CustomButton爲什麼我需要在@selector中傳遞參數。自定義按鈕是註解視圖的一部分。在CustomButton中,我把它作爲屬性UIButtonType,但是在輸出中沒有任何東西出來。輸出是一個沒有任何東西的按鈕,當我想要打開一個視圖控制器時,當我在註解內部觸及時消失。類型UIButtonTypeInfoLight的自定義按鈕
這是CustomButton.m在CustomButton.h
代碼@interface CustomButton : UIButton{
}
@property (nonatomic, strong)NSString * name;
@property (nonatomic, assign)UIButtonType typeButton;
@end
@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;
}
爲什麼當我觸摸了註解內消失
?
如果您只想在loadDetailListViewController方法中訪問一些與註釋相關的信息,則可以使用常規的UIButton並使用calloutAccessoryControlTapped委託方法來訪問view.annotation。 – Anna
我如何?你給我看一個例子嗎? –
見http://stackoverflow.com/questions/4565197/how-to-find-which-annotation-send-showdetails和http://stackoverflow.com/questions/7334068/show-another-view-when-map-註解的是,點擊。 – Anna