I combine Swift code and a third-party library (written in Obj-C). I have a UIViewController with U UISegmentedController in which I want to run every time a segment has been clicked, or the same segment has been clicked again .
In my Swift code, I have the following:
override func viewDidLoad() { super.viewDidLoad() //setup items = ["newTab".localized,"topTab".localized,"categoryTab".localized] carbonTabSwipeNavigation = CarbonTabSwipeNavigation(items: items as [AnyObject], delegate: self) carbonTabSwipeNavigation.insertIntoRootViewController(self) self.style() self.view.userInteractionEnabled = true carbonTabSwipeNavigation.carbonSegmentedControl!.addTarget(self, action:
In the library, I added the following code:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSInteger current = self.selectedSegmentIndex; [super touchesEnded:touches withEvent:event]; if (current == self.selectedSegmentIndex) [self sendActionsForControlEvents:UIControlEventValueChanged]; }
So basically I want to trigger the ValueChanged action every time the user clicks on a segment (even if he is the same segment). It currently starts the second time I click on the same segment, but after that the UISegmentController becomes immune (can no longer switch segments).
source share