User Tools

Site Tools


ios:study-note

iOS学习笔记

NSUserDefaults

    NSString *setting=[[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
    if (!setting) {
        return;
    }
    
    NSDictionary *dictionary=[NSDictionary dictionaryWithContentsOfFile:[setting stringByAppendingPathComponent:@"Root.plist"]];
    NSArray *array = [dictionary objectForKey:@"PreferenceSpecifiers"];
    NSMutableDictionary *registerToDefault=[NSMutableDictionary dictionaryWithCapacity:[array count]];
    for (NSDictionary *item in array) {
         NSString *key = [item objectForKey:@"Key"];
        if (key) {
            [registerToDefault setObject:[item objectForKey:@"DefaultValue"] forKey:@"DefaultValue"];
            break;
        }
    }
    
    [[NSUserDefaults standardUserDefaults] registerDefaults:registerToDefault];
 NSUserDefaults *userDefault=[NSUserDefaults standardUserDefaults];
    NSString *title = [userDefault objectForKey:@"title_preference"];

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
      navigationController=[[UINavigationController alloc] init];
    RootViewController *rootViewController=[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
    rootViewController.title=@"RootView";
    [navigationController pushViewController:rootViewController animated:YES];
    
    [self.window addSubview:[navigationController view]];
    
    [self.window makeKeyAndVisible];

    [rootViewController release];
    
    NSUserDefaults *userDefault=[NSUserDefaults standardUserDefaults];
    NSString *title = [userDefault objectForKey:@"title_preference"];
    if(!title){
        [self performSelector:@selector(restoreBundle)];
    }
    
    
    return YES;
}

/var/www/dokuwiki/wiki/data/pages/ios/study-note.txt · Last modified: 2016/05/05 13:07 by 127.0.0.1