I have a UISegmentedControl with a segmentedValueChanged method on it. I need to find out what was the selected index before this method is called . How to do this?
Use this function:
@property (nonatomic, assign) NSInteger oldSegmentedIndex;
@property (nonatomic, assign) NSInteger actualSegmentedIndex;
.......
- (void)viewDidLoad
{
.......
self.oldSegmentedIndex = -1;
self.actualSegmentedIndex = self.segmentedControl.selectedSegmentIndex;
.......
}
.......
- (IBAction)didSegmentedValueChanged:(id)sender
{
//Do whatever you want
self.oldSegmentedIndex = self.actualSegmentedIndex;
self.actualSegmentedIndex = self.segmentedControl.selectedSegmentIndex;
}
The best way is to keep a variable that holds the last selected index. Then you just check it's value when you need
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With