Skip to content

Value is not updated when change handler is called #55

@koloritcm

Description

@koloritcm

I'm calling a method that updates the UI depending on the current selected segment index. But the code doesn't work because the selectedSegmentIndex has not yet been updated when the handler is called.

You can see in the log from this statement that they are not in sync, selectedSegmentIndex is always one step behind:

self.segmentedControl.changeHandler = ^(NSUInteger newIndex) {
    NSLog(@"New index: %d, Current index: %d", newIndex, self.segmentedControl.selectedSegmentIndex);
    [self updateUI];
};

The regular event works fine and selectedSegmentIndex is updated when the below method is called. But I like blocks much better, too bad it doesn't work as good.

[self.segmentedControl addTarget:self action:@selector(segmentedControlChangedValue) forControlEvents:UIControlEventValueChanged];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions