Set Title String to Settings Bundle iOS

試著忘記壹切 提交于 2019-12-11 13:18:38

问题


I need to localize my setting screen text dynamically based on the iphone setting language/user preferred language. In my scenario, localized text are fetching from the server. I am storing text in database and showing it on the screen. Setting screen should be localized based on the user preferred language/device language. I tried to access the title string of an Item in Root.plist. But it returns value but i need title. How can i access/change the title of the item.

for eg:

{
        DefaultValue = 1;
        Key = "enabled_preference";
        Title = "Keep me logged in";
        Type = PSToggleSwitchSpecifier;
    }

[[NSUserDefaults standardUserDefaults]valueForKey:@"enabled_preference"]; 

which return the value as 1 but i need the title "Keep me logged in" which needs to be changed.

i need a "Title" to be localized (ie) instead of using .lproj file, i have set of localized strings in a dictionary. i need to the set the title with value from dictionary.

How can i accomplish this.

Thanks


回答1:


Here is a way where you can get all the values and keys.

This might help you, get all the keys and traverse everyone to get the key you are looking for

all values:

NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allValues]);

all keys:

NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);

all keys and values:

NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);

using for:

NSArray *keys = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys];

for(NSString* key in keys){
// your code here
NSLog(@"value: %@ forKey: %@",[[NSUserDefaults standardUserDefaults] valueForKey:key],key);
}  


来源:https://stackoverflow.com/questions/22296249/set-title-string-to-settings-bundle-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!