I want to pass the movie url from my dynamically generated button to MediaPlayer:
[button addTarget:self action:@selector(buttonPressed:) withObject:[speakers_mp4 objectAtIndex:[indexPath row]] forControlEvents:UIControlEventTouchUpInside];
but action:@selector() withObject: does not work?
Is there any other solution?
Thanks for help!
Edit. Found a neater way!
One argument that the button can receive is
(id)sender. This means you can create a new button, inheriting from UIButton, that allows you to store the other intended arguments. Hopefully these two snippets illustrate what to do.and
This was my original suggestion.
There is a way to achieve the same result, but it’s not pretty. Suppose you want to add a parameter to your
navigatemethod. The code below will not allow you to pass that parameter tonavigate.To get around this you can move the navigate
methodto a class of it’s own and set the “parameters” as attributes of that class…Of course you can keep the navigate method in the original class and have it called by navAid, as long as it knows where to find it.
Like I said, it’s not pretty, but it worked for me and I haven’t found anyone suggesting any other working solution.