开发者

Saving title of NSSegmentedControl in User defaults

开发者 https://www.devze.com 2023-02-06 06:39 出处:网络
Thanks for the help: I manually set the title of a segController segment from a textField input like this:

Thanks for the help:

I manually set the title of a segController segment from a textField input like this:

NSString  *labelString = [textField stringValue];
(textField.stringValue = labelString);
[segControl setLabel: labelStr开发者_Go百科ing forSegment:8];

I loose the new label when quitting. How can I save the edited segController label string in NSUserDefaults as I would with a text string, like this:

    [[NSUserDefaults standardUserDefaults] setObject: [textField objectValue] forKey: @"newDefault"];

My action needs to occasionally set a new title. Point is the label string is not permanently fixed.

thanks.

Paul.


Assuming you know the segment number, You can do the following:

NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if(defaults) {
    [defaults setValue: [segControl labelForSegment:8] forKey: @"segmentLabel"];
}
else {
    // handle error
}

Alternatively you can just save the string to NSUserDefaults whenever you set the label like in your above example.

0

精彩评论

暂无评论...
验证码 换一张
取 消