Settings bundle in iOS with switch button (Toggle switch) does not get the value of the problem

Source: Internet
Author: User

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
Assuming that the writing is not good please give more advice, assuming that it is good please support a lot of praise. Thank you! Hopy;)

When setting the app's settings bundle in Xcode7.2, it was found that when the bundle element type is toggle switch, the change value is not taken in the app.

Among toggle switch settings such as the following:

Read its value in code in the following way, for example:

BOOL isWarp = [defaults boolForKey:kWarpDrive];_warpDriveLabel.text = isWarp ?

@"Engaged":@"Disabled";

Among the kwarpdrive definitions are as follows:

#define kWarpDrive @"warp"

It is strange to change the state of the button in the settings, and it cannot be reflected in the app ... To be exact, no value is always read in the app regardless of the state of the switch.

The app's settings bundle also has other types of elements, such as text or multiple selection columns, and other elements can read the changed values normally, only toggle switch is not able to.

Then change the strategy when the app starts with its corresponding values:

+(void)regDefaultsFromSettingsBundle{    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];    NSDictionary *dict = @{kWarpDrive:@(YES)};    [defaults registerDefaults:dict];    [defaults synchronize];}

Note that I only register the corresponding value of kwarpdrive, the other value is not tube.

You can then read the switch change value in the app, that's all!!!

The switch button (Toggle switch) in iOS settings bundle does not take the value of the problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.