Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // MainViewController.h
- // ZipWeather
- //
- // Created by AppsAmuck on 10/15/08.
- // Copyright AppsAmuck LLC 2008. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- //#import "ProgressViewController.h"
- @class ProgressViewController;
- @interface MainViewController : UIViewController {
- IBOutlet UIWebView *webView;
- IBOutlet UITextField *textField;
- IBOutlet UITableView *resultsTable;
- IBOutlet UISearchBar *sBar;
- NSMutableArray *contentArray;
- ProgressViewController *progressViewController;
- }
- - (IBAction)goClick;
- @property (nonatomic, retain) ProgressViewController *progressViewController;
- @end
- - (IBAction)goClick {
- [sBar resignFirstResponder];
- ProgressViewController *myView = [[ProgressViewController alloc] init];
- [self.view addSubview:myView.view];
- // fetch html from website
- NSString* weatherXml = [AmuckWeather getWeatherXmlForZipCode: sBar.text];
- NSData* htmlData = [weatherXml dataUsingEncoding:NSUTF8StringEncoding];
- // parse into xml-ish format
- NSError *error;
- NSXMLDocument *document =
- [[NSXMLDocument alloc] initWithData:htmlData options:NSXMLDocumentTidyHTML error:&error];
- NSXMLElement *rootNode = [document rootElement];
- // strip out results table
- NSString *xpathQueryString =@"//table[@id=\"results\"]/tr";
- NSArray *newItemsNodes = [rootNode nodesForXPath:xpathQueryString error:&error];
- // loop storing results
- int count = 0;
- contentArray = [[NSMutableArray arrayWithObjects: nil] retain];
- for (NSXMLElement *node in newItemsNodes)
- {
- // create the result dictionary
- NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
- //add keyed data
- [result setObject:[[node childAtIndex:0] stringValue] forKey:@"street"];
- [result setObject:[[node childAtIndex:1] stringValue] forKey:@"town"];
- [result setObject:[[node childAtIndex:2] stringValue] forKey:@"price"];
- [result setObject:[[node childAtIndex:3] stringValue] forKey:@"sales"];
- if (count > 1) {
- [contentArray addObject: result];
- }
- count++;
- }
- if (count == 0) {
- UIAlertView *searchError = [[UIAlertView alloc] initWithTitle: @"Search Results" message: @"No results found for that search query. Please try again." delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
- [searchError show];
- [searchError release];
- }
- [resultsTable reloadData];
- // [progressViewController.view removeFromSuperview];
- }
Add Comment
Please, Sign In to add comment