我的应用程序崩溃了,请问有什么想法吗?我在我的代码中解析 xml,这里是代码。
如果我删除了这一行,它工作正常 [listItem setValue:currentElementValue forKey:elementName]; 谢谢
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ([elementName isEqualToString:@"channel"]) {
NSLog(@"found channel");
app.listArray = [[NSMutableArray alloc]init];
}
else if([elementName isEqualToString:@"item"]){
listItem = [[NewsList alloc] init];
listItem.title = [attributeDict objectForKey:@"title"];
listItem.description = [attributeDict objectForKey:@"description"];
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if (!currentElementValue) {
currentElementValue = [[NSMutableString alloc] initWithString:string];
}
else
[currentElementValue appendString:string];
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"channel"]) {
return;
}
if ([elementName isEqualToString:@"item"]) {
[app.listArray addObject:listItem];
listItem = nil;
}
else{
NSLog(@"element name = %@", elementName);
[listItem setValue:currentElementValue forKey:elementName];
}
currentElementValue = nil;
}