SVSegmentedControl icon indicating copy to clipboard operation
SVSegmentedControl copied to clipboard

problem with setSelectedSegmentIndex:animated:

Open viking2009 opened this issue 11 years ago • 1 comments

I'm using old way for tracking changes (addTarget:action:forControlEvents:)

- (void)setSelectedSegmentIndex:(NSUInteger)index animated:(BOOL)animated {
    _selectedSegmentIndex = index;

    if(self.superview) {
        [self sendActionsForControlEvents:UIControlEventValueChanged];

sendActionsForControlEvents called even if selected segment not changed

viking2009 avatar Oct 19 '13 19:10 viking2009

this should solve the problem:

- (void)setSelectedSegmentIndex:(NSUInteger)index animated:(BOOL)animated {
    BOOL sendActions = (_selectedSegmentIndex != index);

     _selectedSegmentIndex = index;

     if(self.superview) {
        if (sendActions)
            [self sendActionsForControlEvents:UIControlEventValueChanged];

viking2009 avatar Oct 19 '13 20:10 viking2009