use*_*136 5 localization uisegmentedcontrol ios6
我有一个.xib文件,附带.strings不同语言的文件。该.xib文件包含一个标签和一个UISegmentedControl.
当要求 IB 本地化.xib文件时,我得到以下.strings文件:
"6.segmentTitles[0]" = "title1";
// ...More strings related to the segmented control...
"11.text" = "bla";
Run Code Online (Sandbox Code Playgroud)
'bla' 字符串属于标签。
更改 'bla` 字符串会反映在运行时中,而更改 'title1' 字符串则不会。有谁知道为什么?
这个问题并不新鲜,但由于它仍然没有任何答案,我将添加我的解决方案,因为它可能会帮助其他人。
一般来说,如上所述,UISegmentedControl 段标题不拾取本地化字符串是一个未解决的错误。
- (void)viewDidLoad
{
...
// Locale will be picked automatically by NSBundle.
NSString *resourcePath =[[NSBundle mainBundle] pathForResource:@"MainStoryboard" ofType:@"strings"];
NSDictionary *resourceDict = [NSDictionary dictionaryWithContentsOfFile:resourcePath];
[self.segmentedControl setTitle:[resourceDict objectForKey:@"COo-BO-Ryl.segmentTitles[0]"] forSegmentAtIndex:0];
[self.segmentedControl setTitle:[resourceDict objectForKey:@"COo-BO-Ryl.segmentTitles[1]"] forSegmentAtIndex:1];
}
Run Code Online (Sandbox Code Playgroud)
其中COo-BO-Ryl是segmentedControl 的对象ID。
不是很漂亮,但可以完成工作。