Reputation: 3234
Can we use the addTarget function to hook into the UIControlEventTouchUpInside event with the UIBarButtonItem.
Basically i am trying to hook UIBarButtonItem Play into the UIControlEventTouchUpInside programmticaly without using IB to play the audio file when pressed by using addTarget function.
I m getting error that UIBarButtonItem may not respond to 'addTarget:action:forControlEvents:'
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemPlay
target:self
action:@selector(play:)];
systemItem1.style = UIBarButtonItemStyleBordered;
[systemItem1 addTarget:self action:@selector(playaudio)
forControlEvents:UIControlEventTouchUpInside];
Upvotes: 0
Views: 330
Reputation: 89519
In your init call, you're already setting a target and an action. That's all you need to do.
So take out the addTarget
line as you're already doing the right thing in the init call.
If you want to do both the play and playaudio methods... create one method that calls both and set that as the item's action.
addTarget
exists for UIControl, which a UIBarButtonItem
is not descended from.
Upvotes: 1