What’s the best way to loop through this to get all the XML items out and assign them to the Cell.text as an array?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (Cell == nil) {
Cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
TBXML * XML = [[TBXML tbxmlWithURL:[NSURL URLWithString:@"http://www.tomstest.info/ios/results.xml"]] retain];
TBXMLElement *rootXML = XML.rootXMLElement;
TBXMLElement *results = [TBXML childElementNamed:@"location" parentElement:rootXML];
TBXMLElement *WOEID = [TBXML childElementNamed:@"CompanyName" parentElement:results];
NSString *woeid = [TBXML textForElement:WOEID];
Cell.text = woeid;
return Cell;
}
Thanks
Tom
First, you really shouldn’t download the content of your file in
tableView:cellForRowAtIndexPath:. The method is called once for each cell: you would end up downloading the xml file many times.TBXMLdoes not support XPath queries, so you’ll have to loop through the results.Something like
Then store the titles buffer in a class variable (say cellTitles) and in
tableView:cellForRowAtIndexPath: