ios - 在UIButton的选择器上传递参数

标签 ios parameters uibutton selector

我在detailDisclousure的标注上有一个MKAnnotation按钮。当按下此按钮时,我需要调用一个传递参数的方法,该参数标识调用它的annotation。怎么做?

这是我的viewForAnnotation:

- (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];
}

最佳答案

您只能通过NSIntegertag属性传递任何UIButton

关于ios - 在UIButton的选择器上传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11613906/

相关文章:

IOS - 如何使用 NSBatchDeleteRequest 清理数据库

ios - 如何使用OCMock测试UIButton的setTitle

java - 我将如何相应地编辑我的类以在不带参数的情况下从 main 调用方法?例如 : g. count(文件名) 到 g.count();

Android:如何将参数传递给 AsyncTask 的 onPreExecute()?

swift - 将日期实现到切换按钮

ios - 以编程方式将 UIButton 元素添加到 UIView 不会显示

ios - 当每个部分中的行数不同时,如何获取 numberOfRows 的计数?

iphone - 从手势事件中定位 safari "touches"?

java - 构造函数中有很多参数

iOS:为什么隐藏按钮仍然接收点击事件?