通过UIButton的select器传递参数
我在detailDisclousure
的标注上有一个detailDisclousure
button。 当按下这个button时,我需要调用一个方法来传递一个参数来标识调用它的annotation
。 怎么可能呢?
这是我的观点ForAnnotation:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { if ([annotation isKindOfClass:[Annotation class]]) { static NSString* identifier = @"identifier"; MKPinAnnotationView* pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; if (pinView == nil) { pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]autorelease]; } Annotation *antt = annotation; pinView.canShowCallout = YES; pinView.draggable = YES; UIButton* detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; [detailButton performSelector:@selector(goToViewWithAnnotation:) withObject:antt]; pinView.rightCalloutAccessoryView = detailButton; return pinView; } else { return nil; } }
这是应该用参数调用的方法:
-(void)goToViewWithAnnotation:(Annotation *)annotation { NextViewController *nextView = [[NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil]; nextView.id = annotation.id; [self.navigationController nextView animated:YES]; }
您只能通过UIButton
的tag
属性传递任何NSInteger
。
无法使用-addTarget:action:forControlEvent:
发送数据-addTarget:action:forControlEvent:
for UIButton
:
[detailButton addTarget:self action:@selector(goToViewWithAnnotation:) forControlEvents:UIControlEventTouchUpInside];
尝试用其他方式处理数据,当你触发select器。 就像保存一个指针或者var一样。
UIButton
有这些调用者,你可以看到:
- (void)action - (void)action:(id)sender - (void)action:(id)sender forEvent:(UIEvent *)event
我想你可以在.h文件中添加一个属性(这是(Annotation *)注释)。 然后你可以在“ – (void)goToViewWithAnnotation”方法中使用注释。 或者你可以定制一个inheritanceUIControl的新button