이것은 PLIST 원시 모습입니다 :수 .plist 사전 항목 (아이폰 OS SDK)
나는 PLIST의 전체 항목을 계산하고, 그들처럼 표시 할{
authorLastName = Doe;
authorFirstName = Jane;
imageFilePath = "NoImage.png";
title = "Account Test 1";
year = 2009;
},
{
authorLastName = Doe;
authorFirstName = John;
imageFilePath = "NoImage.png";
title = "Account Test 2";
year = 2009;
},
: '4 개 계정'.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPlistPath = [documentsDirectory
stringByAppendingPathComponent:@"Accounts.plist"];
NSDictionary *plistDict = [[NSDictionary alloc] initWithContentsOfFile:myPlistPath];
NSArray *array = [[plistDict objectForKey:0]
sortedArrayUsingSelector:@selector(compare:)];
return([NSString stringWithFormat:@"%d Accounts", [array count]]);
그러나 결과는 0을 반환합니다. 사전에있는 항목의 개수를 반환하고 싶습니다.
키가 될 수 있습니까? 대신 해당 objectAtIndex 아닌가요? – Garrett
0은 키가 될 수 없으므로 [plistDict objectForKey : 0]은 nil을 반환하므로 모든 메시지가 nil로 반환됩니다. 따라서 배열은 nil이고 [배열 개수]도 0입니다. – Amok
pList에서 ROOT 아래에있는 사전의 수를 계산하려고합니다. 예를 들어 루트 아래에서 항목 1과 항목 2가 항목 1 아래에 5 개의 문자열, 이름, 성, 별명, 번호, 이미지가 있습니다. 얼마나 많은 항목이 있는지 계산하고 Tableview에 표시하기 만하면됩니다. – WrightsCS