vb.net print barcode labels 7: Going the Routesy Way with Core Location, XML, and SQLite in Objective-C

Creation Data Matrix in Objective-C 7: Going the Routesy Way with Core Location, XML, and SQLite

CHAPTER 7: Going the Routesy Way with Core Location, XML, and SQLite
Making Data Matrix 2d Barcode In Objective-C
Using Barcode printer for iPhone Control to generate, create DataMatrix image in iPhone applications.
www.OnBarcode.com
EAN13 Generation In Objective-C
Using Barcode printer for iPhone Control to generate, create EAN13 image in iPhone applications.
www.OnBarcode.com
8. Remember when we created a protocol for the prediction loader We need to attach this protocol to RootViewController to tell BARTPredictionLoader that RootViewController wants to be notified when the data finishes loading. In RootViewController.h, you can add the protocol to the end of the interface declaration:
DataMatrix Creation In Objective-C
Using Barcode creation for iPhone Control to generate, create Data Matrix ECC200 image in iPhone applications.
www.OnBarcode.com
GS1 128 Printer In Objective-C
Using Barcode drawer for iPhone Control to generate, create EAN / UCC - 13 image in iPhone applications.
www.OnBarcode.com
@interface RootViewController : UITableViewController <BARTPredictionLoaderDelegate> { ...
Printing UPC Code In Objective-C
Using Barcode creation for iPhone Control to generate, create UPC-A Supplement 5 image in iPhone applications.
www.OnBarcode.com
Printing QR In Objective-C
Using Barcode encoder for iPhone Control to generate, create QR Code image in iPhone applications.
www.OnBarcode.com
9. Now, we can implement the protocol s xmlDidFinishLoading method in RootViewController so that we can reenable the table after the XML loads.
Barcode Drawer In Objective-C
Using Barcode creation for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
EAN / UCC - 8 Printer In Objective-C
Using Barcode encoder for iPhone Control to generate, create EAN / UCC - 8 image in iPhone applications.
www.OnBarcode.com
- (void)xmlDidFinishLoading { self.tableView.userInteractionEnabled = YES; }
ECC200 Generator In Visual Basic .NET
Using Barcode encoder for .NET framework Control to generate, create DataMatrix image in VS .NET applications.
www.OnBarcode.com
Generating DataMatrix In Java
Using Barcode generator for Android Control to generate, create ECC200 image in Android applications.
www.OnBarcode.com
With that out of the way, we can now focus on loading the correct predictions for the selected station, which means that we need a way to query the loaded XML to get the predictions for the selected stop. We re going to query the XML loaded by BARTPredictionLoader using the XPath implementation provided by libxml2, which we included when we initially created the project. Matt Gallagher, author of the popular Cocoa With Love blog (http://cocoawithlove.com), provides for free use a set of wrapper functions for performing XPath queries. Since libxml2 s C API can be difficult to work with, Matt s PerformXMLXPathQuery function will save us lots of extra time and effort. 10. Now, we ll add a method to BARTPredictionLoader called predictionsForStation that takes the unique station ID as an argument, as shown in Listing 7-8. We ll use this XPath query to find the eta elements that match the unique station ID: //station[abbr='%@']/eta. The PerformXMLXPathQuery function returns an array of dictionaries containing estimates and destinations for the station.
EAN13 Encoder In Java
Using Barcode printer for Java Control to generate, create EAN 13 image in Java applications.
www.OnBarcode.com
PDF-417 2d Barcode Scanner In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Apple s Event-Driven XML Programming Guide for Cocoa (http://developer.apple.
Code 128 Code Set C Generator In None
Using Barcode creator for Office Word Control to generate, create ANSI/AIM Code 128 image in Word applications.
www.OnBarcode.com
UPC-A Supplement 5 Generator In VB.NET
Using Barcode drawer for .NET Control to generate, create UPCA image in VS .NET applications.
www.OnBarcode.com
com/iphone/library/documentation/Cocoa/Conceptual/XMLParsing/ XMLParsing.html) lists several helpful resources for working with XML in Cocoa applications.
Generating Linear 1D Barcode In Java
Using Barcode maker for Java Control to generate, create Linear 1D Barcode image in Java applications.
www.OnBarcode.com
Decoding QR Code ISO/IEC18004 In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Listing 7-8. Loading the Real-Time Predictions for a Station
Paint Data Matrix In None
Using Barcode generator for Font Control to generate, create Data Matrix 2d barcode image in Font applications.
www.OnBarcode.com
GS1 - 13 Creation In None
Using Barcode encoder for Font Control to generate, create European Article Number 13 image in Font applications.
www.OnBarcode.com
- (NSArray*)predictionsForStation:(NSString*)stationId { NSMutableArray *predictions = nil;
Generate PDF417 In VB.NET
Using Barcode drawer for .NET framework Control to generate, create PDF417 image in VS .NET applications.
www.OnBarcode.com
Barcode Recognizer In Java
Using Barcode Control SDK for Eclipse BIRT Control to generate, create, read, scan barcode image in BIRT applications.
www.OnBarcode.com
CHAPTER 7: Going the Routesy Way with Core Location, XML, and SQLite
if (self.predictionXMLData) { NSString *xPathQuery = [NSString stringWithFormat: @"//station[abbr='%@']/eta", stationId]; NSArray *nodes = PerformXMLXPathQuery(self.predictionXMLData, xPathQuery); predictions = [NSMutableArray arrayWithCapacity:[nodes count]]; NSDictionary *node; NSDictionary *childNode; NSArray *children; Prediction *prediction; for (node in nodes) { children = (NSArray*)[node objectForKey:@"nodeChildArray"]; prediction = [[Prediction alloc] init]; for (childNode in children) { [prediction setValue:[childNode objectForKey:@"nodeContent"] forKey:[childNode objectForKey:@"nodeName"]]; } if (prediction.destination && prediction.estimate) { [predictions addObject:prediction]; } [prediction release]; } NSLog(@"Predictions for %@: %@", stationId, predictions); } return predictions; }
11. The PredictionTableViewController class needs a property called predictions to hold the list of predictions that the table will display. Before continuing, you should declare a property on PredictionTableViewController of type NSArray, similar to the one you declared on RootViewController, stations. With this new property in place, we can implement the PredictionTableViewController viewWillAppear method, which will set the predictions into the prediction controller before the view appears. We also need to reload the table data each time the view appears since the user may go back and change the active station. Our viewWillAppear method now will look like Listing 7-9.
Listing 7-9. Loading the Predictions Before the View Appears
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.title = self.station.name;
CHAPTER 7: Going the Routesy Way with Core Location, XML, and SQLite
self.predictions = [[BARTPredictionLoader sharedBARTPredictionLoader] predictionsForStation:self.station.stationId]; [self.tableView reloadData]; }
12. Finally, we re ready to start displaying prediction data. Specifically, our table cells will display the estimate value for each Prediction in the predictions array. You should implement the three table view methods in PredictionTableViewController the same way you did for RootTableViewController. As a reminder, you ll need to implement numberOfSectionsInTableView, numberOfRowsInSection, and cellForRowAtIndexPath. Once you re got those methods in place, you re ready to see your hard work in action. 13. Build and run your application to take a look at the results. When you select a station, you ll see a list of predictions that have been loaded for the station, as shown in Figure 7-20. Note that you may not see any predictions if no trains are currently in service.
Figure 7-20. Viewing the predictions for the selected station
CHAPTER 7: Going the Routesy Way with Core Location, XML, and SQLite
You ll quickly notice a huge problem. We have no idea what the destination is for each train displayed in the predictions. Since the default table view cell only has a single label, we re not able to display as much information as we d like. Creating a custom table view cell solves this problem. 14. Let s create an empty user interface XIB file for our new table view cell. In Xcode, select the Resources folder; then go to File New, and create an empty XIB file called PredictionCell.xib, as shown in Figure 7-21.
Copyright © OnBarcode.com . All rights reserved.