I get some data from an XML file on the Internet using hpple. In my XML file, I have a bunch of different sections from which I get data (about 20).
Here is the code I use to get the data
- (void)getMenuItems:(NSString*)url{ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { //NSLog(@"response == %@", response); [self getDeli:data]; } - (void)getDeli:(NSData*)deliData { TFHpple *Parser = [TFHpple hppleWithHTMLData:deliData]; // 3 NSString *XpathQueryString = self.deliString; NSArray *Nodes = [Parser searchWithXPathQuery:XpathQueryString]; // 4 NSMutableArray *newNodes = [[NSMutableArray alloc] initWithCapacity:0]; for (TFHppleElement *element in Nodes) { // 5 Items *item = [[Items alloc] init]; [newNodes addObject:item]; // 6 item.title = [[element firstChild] content]; item.title = [[[element firstChild] content]stringByReplacingOccurrencesOfString:@"\n" withString:@""]; // 7 item.url = [element objectForKey:@"href"]; } // 8 _deli = newNodes; [self.tableView reloadData];
}
Everything works, and I get the data, the problem is that not all sections have data, and setting the section headers and setting the data in CellForRowAtIndexPath is a problem, because I change it to return the same with the number of sections.
So, I'm looking to find out how many sections will be returned, and set this to the number of sections in the table view, and then set the section headers to the header in the section headers of the xml file, etc.
So, I do not just set the height of the header and row to 0 if the section or cell is empty.
I hope this makes sense ...
Here is most of the xml file
<day name="monday"> <meal name="DINNER"> <counter name="Chefs Choice"> <dish> <name>Vegetable Samosa with Yogurt Sauce</name> </dish> <dish> <name>Tomato Red Pepper Chutney</name> </dish> <dish> <name>Curried Rice & Lentils</name> </dish> </counter> <counter name="EntrΓ©e"> <dish> <name>London Broil</name> </dish> <dish> <name>Oven Roast Rosemary Red Potatoes</name> </dish> <dish> <name>Glazed Fresh Carrots</name> </dish> <dish> <name>Salad Bar</name> </dish> <dish> <name>Cheddar Cheese & Bacon Potato Salad</name> </dish> </counter> <counter name="Grill"> <dish> <name>Hamburger</name> </dish> <dish> <name>Classic Cheeseburger on a Toasted Bun</name> </dish> <dish> <name>Chicken Sandwich</name> </dish> <dish> <name>French Fries</name> </dish> </counter> <counter name="International"> <dish> <name>Shell Pasta</name> </dish> <dish> <name>Spaghetti Sauce with Tomato Bits</name> </dish> <dish> <name>Alfredo Sauce</name> </dish> </counter> <counter name="Pizza"> <dish> <name>Cheese Pizza</name> </dish> <dish> <name>Pepperoni Pizza</name> </dish> <dish> <name>Antipasto Pizza Slice</name> </dish> </counter> <counter name="Soup"> <dish> <name>Tomato Soup Florentine</name> </dish> </counter> <counter name="Vegetable"> <dish> <name>Eggplant Parmesan Casserole</name> </dish> </counter> </meal> </day>
Thanks for the help in advance.
user4048334
source share