하나의보기에서 속성 목록에 데이터를 저장하고 다른보기에서 검색하려고합니다. 나는이 같은 외모를 저장하고있어 데이터의 구조는 :중첩 된 NSDictionary 속성 목록에서 검색
는키 (있는 NSString) 값 (NSDictionary와는)
NSDictionary
은 키와 값이 모두 문자열을 포함합니다.
NSDictionary *savedRSSItemsDictionary = [NSDictionary dictionaryWithContentsOfFile:[self propertyListFilePath]];
NSDictionary *RSSDictionary = [savedRSSItemsDictionary objectForKey:[savedRSSItemsArray objectAtIndex:indexPath.row]];
는 첫 번째 라인 루트를 검색 : 나는 같은 것을 할 데이터를 검색하기 위해 노력하고있어 때
- (IBAction)saveRSSItem:(id)sender {
NSMutableDictionary *dictionary;
if ([[NSFileManager defaultManager] fileExistsAtPath:[self dataFilePath]]){
dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:[self dataFilePath]];
}
else {
dictionary = [[NSMutableDictionary alloc] init];
}
//Create Dictionary to store RSSItem information
NSMutableDictionary *RSSdictionary = [[NSMutableDictionary alloc] init];
if (self.selectedItem.title)
[RSSdictionary setValue:@"title" forKey:self.selectedItem.title];
if (self.selectedItem.summary)
[RSSdictionary setValue:@"summary" forKey:self.selectedItem.summary];
if (self.selectedItem.author)
[RSSdictionary setValue:@"author" forKey:self.selectedItem.author];
if (self.selectedItem.date)
[RSSdictionary setValue:@"date" forKey:self.selectedItem.date];
if (self.selectedItem.content)
[RSSdictionary setValue:@"content" forKey:self.selectedItem.content];
//Add saved RSSItem to dictionary
[dictionary setValue:RSSdictionary forKey:self.selectedItem.title];
//Overwrite the updated dictionary in the property list
NSURL *url = [[NSURL alloc] initFileURLWithPath:[self dataFilePath]];
[dictionary writeToURL:url atomically:YES];
}
: 버튼을 누를 때마다, 나는 구원을 위해이 방법을 발사 사전. 두 번째 줄은 속성 목록 (NSDictionary
)의 첫 번째 행의 값을 검색합니다.
그러나 valueForKey : RSSDictionary
에서 메서드를 사용할 수 없습니다. 그게 아니라고 생각합니다 NSDictionary
? 어떤 아이디어가 NSDictionary
을 속성 목록의 값 필드에 가져올 수없는 이유는 무엇입니까? NSPropertySerialization
을 사용해야합니까?
이상한 들여 쓰기에 불쌍합니다. 이것은 내 첫 게시물입니다 :) –
(a) 나는 당신이 값을 혼동스럽게 생각하고 열쇠를 첫 코드 조각에 넣었습니다. (b)'savedRSSItemsArray'와'indexPath.row'에 무엇이 있는지에 대한 단서를 제공하지 않으므로 다른 사람이 여러분의 두 번째 코드 조각을 돕는 것이 어렵습니다. 디버거에서 코드를 실행하고'RSSDictionary'가 어떻게 설정되는지 살펴 보았습니까? 만약 당신이 다른 변수를보고 거꾸로 작업을 기대하지 않습니다. – CRD
내 코드를 살펴 줘서 고마워. 함수 호출에서 값과 키를 착각하고 있습니다. 그게 가장 가능성이 모든 것을 해결할 것입니다 :) –