我有一个NSMutableArray *myArray
.xml 文件,这是正确解析文件的结果,使用TouchXML
.
我只想用 key 提取所有元素name
并将其存储在一个单独的NSMutableArray
中,但我的 finalNSMutableArray *namesList
无法访问,立即使我的 iPhone 应用程序崩溃,因为它只包含最后一个枚举字符串而不是整个数组。
这是代码:
NSMutableArray *namesList = [[NSMutableArray alloc] initWithArray:myArray copyItems:YES];
int i;
for (i = 0; i < [myArray count]; i++)
{
namesList = [[myArray objectAtIndex:i] objectForKey:@"name"];
NSLog(@"All Names: %@", namesList);
}
NSLog(@"First Name: %@", [namesList objectAtIndex:0]); <-- crashing line
这是 NSLog:
-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x6a42540
2012-04-04 10:34:07.882 Sections[3610:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x6a42540'