爲什麼naam輸出(NULL)? (抱歉,在知道這是基本的東西,但我新用的Plist)讀出Plist問題
這是plist中:
這裏的方法:
- (id) init {
self = [super init];
if (self) {
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSString *plistPath;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
plistPath = [rootPath stringByAppendingPathComponent:@"Data.plist"];
NSLog(@"path: %@",plistPath);
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
}
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
NSLog(@"temp: %@",temp);
if (!temp) {
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
}
self.personName = [temp objectForKey:@"Name"];
NSLog(@"NAAM:%@",[temp objectForKey:@"Name"]);
self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
}
return self;}
謝謝;這樣可行。我怎樣才能(只)讀取電話中的第1項? – Foo 2012-01-05 19:25:53