views:

182

answers:

3

Hi,

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!

A: 

I think the correct method should be : - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

UIControl Reference

Where do you get your method from?

I see that your selector has an argument, that argument will be filled by the runtime system. It will send you back the button through that argument.

Your method should look like:

- (void)buttonPressed:(id)BUTTON_HERE { }

vodkhang
Right, but I want to pass the movie url as parameter to my function buttonPressed. How can I do this?
pbcoder
You have no way to do this. You should store your movie url somewhere like instance variable and then call it there
vodkhang
A: 

UIButton responds to addTarget:action:forControlEvents: since it inherits from UIControl. But it does not respond to addTarget:action:withObject:forControlEvents:

see reference for the method and for UIButton

You could extend UIButton with a category to implement that method, thought.

dkk
A: 

You can sub-class a UIButton named MyButton, and pass the parameter by MyButton's properties.

Then, get the parameter back from (id)sender.

Toro