2012-10-03 47 views
0

我爲iPhone開發了一個應用程序。在這個用戶可以改變按鈕點擊語言。但NSLoalizedString不會轉換該值。iPhone中的本地化無法使用按鈕點擊

代碼

-(IBAction)btn1pressed:(id)sender { 
    SecViewController *sec = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil]; 
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; 

    // NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]); 


    languages [email protected]"en"; 


    [[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"]; 
    [[NSUserDefaults standardUserDefaults] synchronize];  
    NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]); 

    // NSLog(@"%@", NSLocalizedString(@"Subhash", nil)); 
    [self.navigationController pushViewController:sec animated:YES]; 
} 

-(IBAction)btn2pressed:(id)sender { 
    SecViewController *sec = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil]; 
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; 

    // NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]); 


    languages = @"es"; 


    [[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"]; 
    [[NSUserDefaults standardUserDefaults] synchronize];  
    NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]); 

    // NSLog(@"%@", NSLocalizedString(@"Subhash", nil)); 

    [self.navigationController pushViewController:sec animated:YES]; 
} 

-(IBAction)btn3pressed:(id)sender { 
    SecViewController *sec = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil]; 
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; 

    // NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]); 


    languages [email protected]"ja"; 


    [[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"]; 
    [[NSUserDefaults standardUserDefaults] synchronize];  
    NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]); 

    // NSLog(@"%@", NSLocalizedString(@"Subhash", nil)); 

    [self.navigationController pushViewController:sec animated:YES]; 
} 

回答

0

嘗試

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:languages,nil] forKey:@"AppleLanguages"]; 
0

使用NSLocalizedString(),本地化。

也給出相應的本地化字符串。