The Toggle Switch in the settings bundle of iOS cannot get the value.

Source: Internet
Author: User

The Toggle Switch in the settings bundle of iOS cannot get the value.

When setting the settings bundle of the App in Xcode7.2, it is found that when the bundle element type is Toggle Switch, the change value cannot be obtained in the App.

The Toggle Switch settings are as follows:

Read the value in the Code as follows:

BOOL isWarp = [defaults boolForKey:kWarpDrive];_warpDriveLabel.text = isWarp ? @"Engaged":@"Disabled";

KWarpDrive is defined as follows:

#define kWarpDrive @"warp"

It is strange that the status of the switch button is changed in settings and cannot be reflected in the App... Specifically, NO value is always read in the App regardless of the switch status.

The settings bundle of the App also has other types of elements, such as text or multi-choice columns. Other elements can normally read the changed values, but the Toggle Switch cannot.

Then, when the App is started, the corresponding value is registered:

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

Note that I only registered the value corresponding to kWarpDrive.

Then, the value changed by the switch can be read normally in the App. That's All !!!

Related Article

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.