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