我正在尝试根据 setting.bundle 中的切换开关状态更改我的应用程序的 mainView。我想设置的默认设置为 NO,我已经设置了。但似乎我遗漏了一些东西,我似乎可以通过我的代码更改视图的唯一方法是更改默认值。我在 applicationDidFinishLaunchingWithOptions 的 delegate.m 文件中执行此操作。请任何帮助都会很棒!
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Registers the defaults.
NSUserDefaults *metricDefaults = [NSUserDefaults standardUserDefaults];
[metricDefaults registerDefaults:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:@"metric_preferences"]];
BOOL metricDisabled = [metricDefaults boolForKey:@"metric_preference"];
[metricDefaults synchronize];
//Change MainView based on Metric setting.
if (metricDisabled) {
//Standard View.
MainViewController *aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
self.mainViewController = aController;
[aController release];
mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window addSubview:[mainViewController view]];
[window makeKeyAndVisible];
return YES;
} else {
//Metric View.
MainViewController *aController = [[MainViewController alloc] initWithNibName:@"MainViewMetric" bundle:nil];
self.mainViewController = aController;
[aController release];
mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window addSubview:[mainViewController view]];
[window makeKeyAndVisible];
return YES;
}
}