I am making a utility application. On the flipside, I have a UISegmentedControl. Depending on the user's selection, a label on the main view will say one of two things. And while this functionality works, for whatever reason, whenever the user goes to the settings (flipside) of the app, the segmentedcontrol has the same part of the control highlighted. If the user presses part 0, then returns to the app, then goes back to the settings panel, the segmented control will show part 0 selected. If the user presses part 1, then returns to the app, then goes back to the settings panel, the segmented control will again show part 0 selected. I can disable this, by not choosing either as selected, but the problem still remains. When the user makes a selection, then goes to the main view, then returns to the settings pane, again nothing is selected. How can I retain the user's selecting, so that when they return to the settings pane, it will have highlighted his or her most recent selection?
Asked
Active
Viewed 152 times
0
-
consider using global variables: http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html or http://stackoverflow.com/questions/231947/referencing-appdelegate-instance-variables – tipycalFlow Aug 17 '11 at 05:13
1 Answers
0
NSUserDefaults ended up being the answer:
[[NSUserDefaults standardUserDefaults] setInteger:segmentedControl.selectedSegmentIndex
forKey:@"someKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
Later, if you want to retrieve it:
NSInteger selectedSegment = [[NSUserDefaults standardUserDefaults]
integerForKey:@"someKey"];

eric.mitchell
- 8,817
- 12
- 54
- 92
-
I am trying to save NSUserDefaults for an segment. Could you provide the code you used to save the segment :) – Dec 21 '12 at 02:56
-
Thanks, one more question i can we create an if or switch statement using segmentcontrol :) – Dec 21 '12 at 03:24
-
This is not the place to ask a question. If you have another problem, please start a new start a new question. – eric.mitchell Dec 21 '12 at 16:25
-
Soory, I lost my privilege to ask question, Your help would be greatly appreciated.. – Dec 21 '12 at 17:53