开发者

Where do I put registerDefaults?

I want to l开发者_Python百科oad and save settings. I don't know where I put registerDefaults. I put it in loadSetting. I think I did wrong. Do I have to put it at the end of application didFinishLaunch?

  - (void)loadSettings {    
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

        NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES], @"key1",
                         [NSNumber numberWithBool:NO], @"key2",
                         nil];
        [defaults registerDefaults:dictionary];

        key1Value = [defaults boolForKey:@"key1"];
        key2Value = [defaults boolForKey:@"key2"];
    }

    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:  NSDictionary *)launchOptions  {    
        [self loadSettings];

    }


It looks ok to me. I think as long as you call it before any views are loaded, you should be fine.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜