ios - Handle tap on same segmented button? -
i'm trying handle tap event on segmented control, when selected button clicked again. example, screenshot below "second" selected, how handle action when "second" button clicked again?
i tried iboutlet
, triggers when value has changed. tried code below, same thing triggers when value changes. in both cases while "second" selected, clicking "second" again not fire anything. there way this?
segmentedcontrol.addtarget(self, action: "segementedanytap:", forcontrolevents: .allevents)
this works me, adding gesture recogniser uisegmentedcontrol
- (void)viewdidload { [super viewdidload]; [self.segmentedcontrol addtarget:self action:@selector(valuechanged:) forcontrolevents:uicontroleventvaluechanged]; uitapgesturerecognizer *tapgesture = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(touched:)]; [self.segmentedcontrol addgesturerecognizer:tapgesture]; } - (void)valuechanged:(id)sender { // value change code } - (void)touched:(id)sender { // code check if segmented controls index has not changed. // execute desired functionality }
Comments
Post a Comment