В настоящее время я показываю свой plist, используя код ниже, который работает, однако это кажется мне неэффективным, и я полагаю, что существует более чистый подход.Отображение plist на основе переменной
if ([self.title isEqual: @"How to wear a Kilt"]){
NSString *path = [[NSBundle mainBundle] pathForResource:@"wearAKilt" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
thumbImg = [dict objectForKey:@"thumbImg"];
stepLabel = [dict objectForKey:@"stepLabel"];
descLabel = [dict objectForKey:@"descLabel"];
}
// Find out the path of recipes.plist
else if ([self.title isEqual: @"How to tie a cravat"]){
NSString *path = [[NSBundle mainBundle] pathForResource:@"wearACravat" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
thumbImg = [dict objectForKey:@"thumbImg"];
stepLabel = [dict objectForKey:@"stepLabel"];
descLabel = [dict objectForKey:@"descLabel"];
}
else if ([self.title isEqual: @"How to wear a sporran"]){
NSString *path = [[NSBundle mainBundle] pathForResource:@"wearASporran" ofType:@"plist"];
// Load the file content and read the data into arrays
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
thumbImg = [dict objectForKey:@"thumbImg"];
stepLabel = [dict objectForKey:@"stepLabel"];
descLabel = [dict objectForKey:@"descLabel"];
}
Я попытался с помощью, если заявление только на * пути, но это (как и ожидалось) выдает ошибку undeclared identifier path
.
if ([self.title isEqual: @"How to wear a Kilt"]){
NSString *path = [[NSBundle mainBundle] pathForResource:@"wearAKilt" ofType:@"plist"];
} else if ([self.title isEqual: @"How to tie a cravat"]) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"wearACravat" ofType:@"plist"];
}
Любые предложения?
сейчас я чувствую себя идиотом. Просто. Из интереса есть хорошая документация о том, как «использовать словарь для сопоставления из входящей строки в соответствующее имя файла» – user2966586
im, устанавливая заголовок на основе представления таблицы из-за использования локалей. – user2966586
Добавлен быстрый текст кода. Ключи должны быть связаны с тем, как вы идеально настроили название ... – Wain