Guest User

Untitled

a guest
Jun 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. //
  2. // MainViewController.h
  3. // ZipWeather
  4. //
  5. // Created by AppsAmuck on 10/15/08.
  6. // Copyright AppsAmuck LLC 2008. All rights reserved.
  7. //
  8.  
  9. #import <UIKit/UIKit.h>
  10. //#import "ProgressViewController.h"
  11.  
  12. @class ProgressViewController;
  13.  
  14. @interface MainViewController : UIViewController {
  15. IBOutlet UIWebView *webView;
  16. IBOutlet UITextField *textField;
  17. IBOutlet UITableView *resultsTable;
  18. IBOutlet UISearchBar *sBar;
  19. NSMutableArray *contentArray;
  20. ProgressViewController *progressViewController;
  21. }
  22. - (IBAction)goClick;
  23.  
  24. @property (nonatomic, retain) ProgressViewController *progressViewController;
  25.  
  26. @end
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. - (IBAction)goClick {
  34.  
  35. [sBar resignFirstResponder];
  36.  
  37. ProgressViewController *myView = [[ProgressViewController alloc] init];
  38. [self.view addSubview:myView.view];
  39.  
  40. // fetch html from website
  41. NSString* weatherXml = [AmuckWeather getWeatherXmlForZipCode: sBar.text];
  42. NSData* htmlData = [weatherXml dataUsingEncoding:NSUTF8StringEncoding];
  43.  
  44. // parse into xml-ish format
  45. NSError *error;
  46. NSXMLDocument *document =
  47. [[NSXMLDocument alloc] initWithData:htmlData options:NSXMLDocumentTidyHTML error:&error];
  48. NSXMLElement *rootNode = [document rootElement];
  49.  
  50. // strip out results table
  51. NSString *xpathQueryString =@"//table[@id=\"results\"]/tr";
  52. NSArray *newItemsNodes = [rootNode nodesForXPath:xpathQueryString error:&error];
  53.  
  54. // loop storing results
  55. int count = 0;
  56. contentArray = [[NSMutableArray arrayWithObjects: nil] retain];
  57. for (NSXMLElement *node in newItemsNodes)
  58. {
  59. // create the result dictionary
  60. NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
  61.  
  62. //add keyed data
  63. [result setObject:[[node childAtIndex:0] stringValue] forKey:@"street"];
  64. [result setObject:[[node childAtIndex:1] stringValue] forKey:@"town"];
  65. [result setObject:[[node childAtIndex:2] stringValue] forKey:@"price"];
  66. [result setObject:[[node childAtIndex:3] stringValue] forKey:@"sales"];
  67.  
  68. if (count > 1) {
  69. [contentArray addObject: result];
  70. }
  71. count++;
  72. }
  73.  
  74. if (count == 0) {
  75. UIAlertView *searchError = [[UIAlertView alloc] initWithTitle: @"Search Results" message: @"No results found for that search query. Please try again." delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
  76. [searchError show];
  77. [searchError release];
  78. }
  79.  
  80. [resultsTable reloadData];
  81.  
  82. // [progressViewController.view removeFromSuperview];
  83. }
Add Comment
Please, Sign In to add comment