UITableViewController, XML parsing, and simple map combination, ofbizcontroller. xml
Then, my code is output in the above Order.
#import <Foundation/Foundation.h>#import <MapKit/MapKit.h>@interface MapAnnotation : NSObject<MKAnnotation>@property(nonatomic,readwrite) CLLocationCoordinate2D coordinate;@property(nonatomic,strong) NSString* titler;-(id)initWithTirle:(NSString *)titler andCoordinate:(CLLocationCoordinate2D)coordinate2d;@end
#import "MapAnnotation.h"@implementation MapAnnotation-(id)initWithTirle:(NSString *)titler andCoordinate:(CLLocationCoordinate2D)coordinate2d{ self.titler=titler; self.coordinate=coordinate2d; return self;}@end
#import <UIKit/UIKit.h>#import "RootTableViewController.h"@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end
#import "AppDelegate.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window.rootViewController=[[UINavigationController alloc] initWithRootViewController:[[RootTableViewController alloc]initWithStyle:UITableViewStylePlain]]; return YES;}
#import <UIKit/UIKit.h>#import <MapKit/MapKit.h>#import <CoreLocation/CoreLocation.h>@interface ViewController : UIViewController<MKMapViewDelegate>@property(strong,nonatomic)NSString *latitude;@property(strong,nonatomic)NSString *longitude;@end
# Import "ViewController. h "# import" MapAnnotation. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // initialize the size of your map on your mobile phone. MKMapView * mapView = [[MKMapView alloc] initWithFrame: self. view. frame]; // follows the mapView protocol. delegate = self; // The current map spreads mapView with coordinates as the center point. centerCoordinate = CLLocationCoordinate2DMake ([self. latitude doubleValue], [self. longpolling doubleValue]); // map type mapView. mapType = MKMapTypeHybrid; // create the location CLLocationCoordinate2D location; // the longitude and latitude location of the location. latitude = [self. latitude doubleValue]; location. longpolling = [self. longpolling doubleValue]; // use a pin to receive your location MapAnnotation * newAnnotation = [[MapAnnotation alloc] initWithTirle: @ "Apple Head quaters" andCoordinate: location]; // Add the map to your map [mapView addAnnotation: newAnnotation]; // Add the map to your page [self. view addSubview: mapView]; self. navigationItem. leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @ "back" style: 2 target: self action: @ selector (backPage)];}-(void) mapView :( MKMapView *) mv didAddAnnotationViews :( NSArray *) views {MKAnnotationView * annotationView = [views objectAtIndex: 0]; // the id of the proxy property call method <MKAnnotation> mp = [annotationView annotation]; // scale the X axis and Y axis you see. MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance ([mp coordinate], 1500,150 0); // whether the mv is scaled [mv setRegion: region animated: YES]; // whether the mv implements mp [mv selectAnnotation: mp animated: YES];}-(void) backPage {[self. navigationController popToRootViewControllerAnimated: YES];}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end
#import <UIKit/UIKit.h>#import "ViewController.h"@interface RootTableViewController : UITableViewController<NSXMLParserDelegate>@property(strong,nonatomic)NSMutableArray *arr;@property(strong,nonatomic)NSMutableDictionary *dic;@property(strong,nonatomic)NSString *str;@end
# Import "RootTableViewController. h "@ interface RootTableViewController () @ end @ implementation RootTableViewController-(void) viewDidLoad {[super viewDidLoad]; self. title = @ "City list"; NSURL * url = [NSURL URLWithString: @ "http://www.meituan.com/api/v1/divisions? Mtt = 1. help % 2Fapi. 0.0.im7coqq1 "]; NSData * data = [NSData dataWithContentsOfURL: url]; NSXMLParser * parser = [[NSXMLParser alloc] initWithData: data]; parser. delegate = self; BOOL bol = [parser parse]; NSLog (@ "% d", bol); [self. tableView registerClass: [UITableViewCell class] forCellReuseIdentifier: @ "reuseIdentifier"];}-(void) parserDidStartDocument :( NSXMLParser *) parser {self. arr = [NSMutableArray array];}-(void) parserDidEndDocument :( NSXMLParser *) parser {NSLog (@ "% @", self. arr);}-(void) parser :( NSXMLParser *) parser didStartElement :( NSString *) elementName namespaceURI :( nullable NSString *) namespaceURI qualifiedName :( nullable NSString *) qName attributes :( NSDictionary <NSString *, NSString *> *) attributeDict {if ([elementName isenttostring: @ "division"]) {self. dic = [NSMutableDictionary dictionary]; [self. dic setDictionary: attributeDict] ;}}- (void) parser :( NSXMLParser *) parser didEndElement :( NSString *) elementName namespaceURI :( nullable NSString *) namespaceURI principal :( nullable NSString *) qName {if ([elementName isinclutostring: @ "name"] | [elementName isinclutostring: @ "latitude"] | [elementName isinclutostring: @ "longpolling"]) {[self. dic setObject: self. str forKey: elementName];} else if ([elementName isinclutostring: @ "division"]) {[self. arr addObject: self. dic] ;}}-(void) parser :( NSXMLParser *) parser foundCharacters :( NSString *) string {self. str = string;}-(void) didreceivemorywarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} # pragma mark-Table view data source-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return 1;}-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return self. arr. count;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {UITableViewCell * cell = [tableView metadata: @ "reuseIdentifier" forIndexPath: indexPath]; cell. textLabel. text = self. arr [indexPath. row] [@ "name"]; return cell;}-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {NSLog (@ "% @", self. arr [indexPath. row]); ViewController * viewvc = [[ViewController alloc] init]; viewvc. longpolling = self. arr [indexPath. row] [@ "longpolling"]; viewvc. latitude = self. arr [indexPath. row] [@ "latitude"]; [self. navigationController pushViewController: viewvc animated: YES];}