Passing parameters on button action:@selector

前端 未结 11 1334
生来不讨喜
生来不讨喜 2020-11-27 17:29

I want to pass the movie url from my dynamically generated button to MediaPlayer:

[button addTarget:self action:@selector(buttonPressed:) withObject:[speaker         


        
11条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 18:04

    I have another solution in some cases.

    store your parameter in a hidden UILabel. then add this UILabel as subview of UIButton.

    when button is clicked, we can have a check on UIButton's all subviews. normally only 2 UILabel in it.

    one is UIButton's title, the other is the one you just added. read that UILabel's text property, you will get the parameter.

    This only apply for text parameter.

提交回复
热议问题