ios - UIButton UIControl target action 2 actions for single button -
i have button has selected , non-selected state.
my target action code button this:
nsarray *targets = [mybutton actionsfortarget:self forcontrolevent:uicontroleventtouchupinside]; if ([targets count] == 0) { [mybutton addtarget:self action:@selector(save:) forcontrolevents:uicontroleventtouchupinside];
when button pressed, goes selected state in method.
if button selected, different action should called. there unintended consequence doing way or there way add actions uicontrolstate instead?
if (mybutton.selected == no){ [mybutton addtarget:self action:@selector(save:) forcontrolevents:uicontroleventtouchupinside]; } else{ [mybutton addtarget:self action:@selector(delete:) forcontrolevent:uicontroleventtouchupinside]; }
-(ibaction)mybutton:(id)sender { uibutton *btn = (uibutton*)sender; btn.selected = !btn.selected; if(btn.selected) { //do whatever want when button selected [self delete]; } else { //do whatever want when button isdeselected [self save]; } }
Comments
Post a Comment