Pass parameter on selector of UIButton

前端 未结 3 1777
旧时难觅i
旧时难觅i 2021-01-25 09:09

I have a detailDisclousure button on the callout of a MKAnnotation. When this button is pressed I need to call a method passing a parameter that identi

相关标签:
3条回答
  • 2021-01-25 09:37

    you can pass any NSInteger via the tag property of the UIButton only.

    0 讨论(0)
  • 2021-01-25 09:38

    I think you can add a property(which is (Annotation *)annotation) in .h file. Then you can use annotation in the "-(void)goToViewWithAnnotation" method. Or you can customized a new button which inherits UIControl

    0 讨论(0)
  • 2021-01-25 09:44

    It's not possible to send data with the -addTarget:action:forControlEvent: for UIButton:

    [detailButton addTarget:self action:@selector(goToViewWithAnnotation:) forControlEvents:UIControlEventTouchUpInside];
    

    Try to handle the data with some other way, when you trigger the selector. Like saving a pointer or var as you like.

    UIButton have these callers as you can see:

    - (void)action
    - (void)action:(id)sender
    - (void)action:(id)sender forEvent:(UIEvent *)event
    
    0 讨论(0)
提交回复
热议问题