在我的应用程序中,我需要提供三种语言支持。我的默认语言是英语。一旦用户在设置控制器中选择了其他语言,整个应用程序应更改为该特定语言。为此,我决定创建一个包含所有三种语言及其数据的 plist 文件。现在我的默认语言是英语,这很好。现在我在 LanguageController 中使用 plist 更改了语言并推送到主控制器。我的家庭控制器未收到所选语言(法语)字符串。这是我的代码,
//LanguageController.h
NSMutableDictionary *allDictElements;
NSString *selectedLanguage1;
NSArray *dummy;
@property(nonatomic,retain) NSMutableDictionary *allDictElements;
@property(nonatomic,retain) NSString *selectedLanguage1;
@property(nonatomic,retain) NSArray *dummy;
//LanguageController.m
@synthesize allDictElements,selectedLanguage1,dummy;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *path= [[NSBundle mainBundle] pathForResource:@"Language" ofType:@"plist"];
allDictElements = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSLog(@"%@allDictElements",allDictElements);
LeeValleyHomeViewController *homeController = [[LeeValleyHomeViewController alloc] initWithNibName:@"LeeValleyHomeViewController" bundle:[NSBundle mainBundle]];
if (indexPath.row ==0)
{
//bookshelf button
NSMutableDictionary *english=[[NSMutableDictionary alloc]init];
english=[allDictElements objectForKey:@"English Language"];
dummy=[english objectForKey:@"English"];
selectedLanguage1=[dummy objectAtIndex:0];
NSLog(@"english bookshelf button:%@",selectedLanguage1);
homeController.selectedLanguage = selectedLanguage1;
NSLog(@"sel lang:%@",homeController.selectedLanguage);
} else if (indexPath.row ==1) {
//bookshelf button
NSMutableDictionary *french=[[NSMutableDictionary alloc]init];
french=[allDictElements objectForKey:@"French Language"];
dummy=[french objectForKey:@"French"];
selectedLanguage1=[dummy objectAtIndex:0];
NSLog(@"french bookshelf button:%@",selectedLanguage1);
homeController.selectedLanguage = selectedLanguage1;
NSLog(@"sel lang:%@",homeController.selectedLanguage);
} else {
NSMutableDictionary *spanish=[[NSMutableDictionary alloc]init];
spanish=[allDictElements objectForKey:@"Spanish Language"];
dummy=[spanish objectForKey:@"Spanish"];
selectedLanguage1=[dummy objectAtIndex:0];
NSLog(@"spanish bookshelf button:%@",selectedLanguage1);
homeController.selectedLanguage = selectedLanguage1;
NSLog(@"sel lang:%@",homeController.selectedLanguage);
}
[self.navigationController pushViewController:homeController animated:YES];
}
在这个控制器中,我很好地接收到选定的语言字符串。
//LeeValleyHomeViewController.h
NSString *selectedLanguage;
@property (nonatomic,retain) NSString *selectedLanguage;
//LeeValleyHomeViewController.m
@synthesize selectedLanguage;
- (void)viewDidLoad
{
LanguageViewController lvc = [LanguageViewController alloc]init];
bookshelfbtn.titleLabel.text = lvc.selectedLanguage1;
NSLog(@"button title:%@",bookshelfbtn.titleLabel.text);
//bookshelfbtn.titleLabel.text = selectedLanguage;
}
在此控制器中,没有收到该字符串值。我的代码有什么问题?或者我该怎么做?提前致谢。