Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
I am using a segmented control in my settings view to make certain changes. Everything is working fine for when I change values on the control, but how do I get it to retain the index based off of the NSUserDefault?
 
Not sure I understand the question.
NSUserDefaults is a dictionary and does not like the zero form an integer (segmentIndex). If you make your int into an NSString it can be stored in the Dictionary with out problems even when zero. Get it back with intValue.

- Olaf
 
Not sure I understand the question.
NSUserDefaults is a dictionary and does not like the zero form an integer (segmentIndex). If you make your int into an NSString it can be stored in the Dictionary with out problems even when zero. Get it back with intValue.

- Olaf

Finally got it working. Problem I had originally was I set the int in wrong order for segmentedcontrol. Here is what I ended with:
Code:
-(void)viewWillAppear:(BOOL)animated {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSURL *sermons = [defaults URLForKey:@"sermon"];
    NSString *absolutely = sermons.absoluteString;
    NSLog(@"%@", absolutely);
    if ([absolutely isEqualToString:@"http://www.bellavenue.org/sermons.htm"]) {
        segment.selectedSegmentIndex = 1;
    }
    if ([absolutely isEqualToString:@"http://www.316apps.com/iphonesermons.html"]) {
        segment.selectedSegmentIndex = 0;
    }

}
 
Not sure I understand the question.
NSUserDefaults is a dictionary and does not like the zero form an integer (segmentIndex). If you make your int into an NSString it can be stored in the Dictionary with out problems even when zero. Get it back with intValue.

I would recommend using NSNumber rather than NSString to store ints in NSUserDefaults.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.