Do not listen to the guy above. The first thing you should know is that the UISegmentedControl starts from scratch. So, the first bar is 0, the second is 1, the third is 2, etc. .... If you want to start from zero, just add it to the integer after receiving the value. (See below) To get its value when it changes, connect the IBAction method and connect it to your UISegmentedControl. Do the action with valueChanged, not touchUpInside. Then, as part of your IBAction method, let's say it's called theMethod, use this code.
-(IBAction)theMethod { int theInteger; theInteger = [segmentedController selectedSegmentIndex];
Then you can save the integer using NSUserDefaults.
Please note: you will need to convert the integer to NSNumber if you want to save it, because you cannot save integers or variables, you can only save objects. For this, I would use the following:
NSNumber *myNumber = [NSNumber numberWithInt:theInteger];
source share