行数是使用RaptureXML返回不正确的数字

我目前使用RaptureXML从表视图内的URL tio显示拉入数据。 我设法抓住每一个我需要的string,并将其添加到我的数组,如下所示:

- (void)loadURL { RXMLElement *rootXML = [RXMLElement elementFromURL:[NSURL URLWithString:@"http://api.somexml.com/xml"]]; NSLog(@"%@ %@", rootXML.tag, [rootXML attribute:@"totalEntries"]); [rootXML iterateWithRootXPath:@"//event" usingBlock:^(RXMLElement *event) { // NSLog(@"Event - URI: %@", [event attribute:@"uri"]); // NSLog(@"Event - Venue: %@", [event attribute:@"displayName"]); // NSLog(@"Event - Type: %@", [event attribute:@"type"]); [rootXML iterateWithRootXPath:@"//location" usingBlock: ^(RXMLElement *location) { // NSLog(@"Location - City: %@",[location attribute:@"city"]); // NSLog(@"Location - Latitude : %@",[location attribute:@"lat"]); // NSLog(@"Location - Longitude: %@",[location attribute:@"lng"]); [rootXML iterateWithRootXPath:@"//start" usingBlock:^(RXMLElement *start) { // NSLog(@"Start - Time: %@",[start attribute:@"time"]); // NSLog(@"Start - Date: %@",[start attribute:@"date"]); [rootXML iterateWithRootXPath:@"//performance" usingBlock:^(RXMLElement *performance) { // NSLog(@"Performance - Artist: %@",[start attribute:@"displayName"]); [events addObject:[NSArray arrayWithObjects: [event attribute:@"uri"], [event attribute:@"displayName"], [event attribute:@"type"], [location attribute:@"city"], [location attribute:@"lat"], [location attribute:@"lng"], [start attribute:@"time"], [start attribute:@"date"], [performance attribute:@"displayName"], nil]]; }]; }]; }]; }]; } 

问题是,当我分配的行数,它返回一个大数,而不是6。

  return [events count]; 

这是XML文件的样子:

 <resultsPage totalEntries="6" perPage="50" page="1" status="ok"> <results> <event uri="http://somexml.com/xml" popularity="0.863682" displayName="Radio 1's Hackney Weekend 2012" id="9234656" type="Festival" status="ok"> <location city="London, UK" lng="-0.128" lat="51.5078"/> <series displayName="Radio 1's Hackney Weekend"/> <end time="" date="2012-06-24" datetime=""/> <start time="" date="2012-06-23" datetime=""/> <performance displayName="Lucy Labeaux" billingIndex="5" id="23336188" billing="headline"> <artist uri="http://www.somexml.com/artistxml" displayName="Lucy Labeaux" id="1168415"> <identifier href="http://somexml.com.xml" mbid="4593d49a-7f67-46ba-9ec0-126bd676286f"/> </artist> </performance> 

感谢您的帮助!

**

获取有关我的数组对象的错误。

**

所以我想出了一些不断运行代码的东西。 如果你看下面我分3次添加对象到我的数组。

 - (void)loadURL { RXMLElement *rootXML = [RXMLElement elementFromURL:[NSURL URLWithString:@"http://somexml.com/xml"]]; NSLog(@"%@ %@", rootXML.tag, [rootXML attribute:@"totalEntries"]); [rootXML iterateWithRootXPath:@"//event" usingBlock:^(RXMLElement *event) { [events addObject:[NSArray arrayWithObjects: [event attribute:@"uri"], [event attribute:@"displayName"], [event attribute:@"type"], nil]]; }]; [rootXML iterateWithRootXPath:@"//location" usingBlock: ^(RXMLElement *location) { [events addObject:[NSArray arrayWithObjects: [location attribute:@"city"], [location attribute:@"lat"], [location attribute:@"lng"], nil]]; }]; [rootXML iterateWithRootXPath:@"//start" usingBlock:^(RXMLElement *start) { [events addObject:[NSArray arrayWithObjects: [start attribute:@"time"], [start attribute:@"date"], nil]]; }]; } 

现在,当我打电话给我的对象,所以我可以链接到他们的接口,我做了以下几点:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { EventsCell *cell = (EventsCell *)[tableView dequeueReusableCellWithIdentifier:@"EventsCell"]; cell.venueLabel.text = [NSString stringWithFormat:@"%@",[[events objectAtIndex:indexPath.row] objectAtIndex:2]]; return cell; 

}

我意识到,而不是索引创build总共8个对象,它只是创build3。每次我添加新的对象,它将它添加到这3个索引。 例如,如果我将我的场地标签分配给objectAtIndex 2,我不仅得到6行,标签显示types,还有6行显示时间。

这是我的viewDidLoad的外观:

 - (void)viewDidLoad { [super viewDidLoad]; self.events = [[NSMutableArray alloc] init]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self loadURL]; dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); }); } 

看到没有人回答这个问题是“答案”,而是在评论中留下了答案,我只是接受这个答案。