以下是我收到错误的代码:
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
currentElement = [elementName copy];
NSLog(@"didEndElement : %@",currentElement);
if ([currentElement isEqualToString:@"NewDataSet"]) {
[dicEvent setObject:catIDArray forKey:@"term_id"];
[dicEvent setObject:catArray forKey:@"cat_name"];
[dicEvent setObject:catTimgArray forKey:@"thumb_nail_url"];
[dicEvent setObject:catLimgArray forKey:@"large_image_url"];
[xmlData addObject:[dicEvent copy]];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
if ([catArray count] == 0) {
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@"Data"
message:@"No record found."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
[activityIndicator stopAnimating];
activityIndicator.hidesWhenStopped = YES;
}
else {
NSLog(@"adding category : %@", xmlData);
[tblView reloadData];
}
}
当表加载时我在这个方法中得到错误....它在行返回时给出错误[xmlData count];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"[xmlData count] 2 : %d", [xmlData count]);
return [xmlData count];
}
答案 0 :(得分:0)
您发布的第一种方法存在内存泄漏。您创建了elementName
字符串的副本,但从未发布它。此外,您尚未指定如何初始化xmlData
,但我会冒险猜测并说您使用您不拥有的数组初始化它。在init
方法中,请确保您拥有:
xmlData = [[NSMutableArray alloc] init];
这可确保您拥有该对象。在dealloc
方法中,您也应该[xmlData release]
。
答案 1 :(得分:0)
NSMutableArray *xmlData = [[NSMutableArray alloc] init];
并将NSLog放入