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];
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:
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.