UITableViewController和XML解析还有地图的简单结合
然后我的代码就按照上面的这个顺序输出。
#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];
//初始化你的地图在手机上的大小
MKMapView *mapView=[[MKMapView alloc] initWithFrame:self.view.frame];
//遵循协议
mapView.delegate = self;
//当前地图以坐标为中心点扩散
mapView.centerCoordinate=CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
//地图类型
mapView.mapType=MKMapTypeHybrid;
//创建位置
CLLocationCoordinate2D location;
//位置的经度纬度 location.latitude=[self.latitude doubleValue];
location.longitude=[self.longitude doubleValue];
//用大头针来接收你所在的位置
MapAnnotation *newAnnotation=[[MapAnnotation alloc] initWithTirle:@"Apple Head quaters" andCoordinate:location];
//添加到你的地图上
[mapView addAnnotation:newAnnotation];
//把地图添加你的页面上
[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];
//代理属性 调用方法
id<MKAnnotation>mp=[annotationView annotation];
//缩放你所看到的的X轴和Y轴
MKCoordinateRegion region=MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);
//mv 是否实现缩放
[mv setRegion:region animated:YES];
//mv 是否实现mp
[mv selectAnnotation:mp animated:YES]; } -(void)backPage
{
[self.navigationController popToRootViewControllerAnimated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// 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=@"城市列表";
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 isEqualToString:@"division"]) {
self.dic=[NSMutableDictionary dictionary];
[self.dic setDictionary:attributeDict]; }
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName
{
if ([elementName isEqualToString:@"name"]||[elementName isEqualToString:@"latitude"]||[elementName isEqualToString:@"longitude"]) {
[self.dic setObject:self.str forKey:elementName];
}
else if ([elementName isEqualToString:@"division"])
{
[self.arr addObject:self.dic];
}
} - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
self.str=string;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// 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 dequeueReusableCellWithIdentifier:@"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.longitude=self.arr[indexPath.row][@"longitude"];
viewvc.latitude=self.arr[indexPath.row][@"latitude"];
[self.navigationController pushViewController:viewvc animated:YES]; }
UITableViewController和XML解析还有地图的简单结合的更多相关文章
- glib简单记录包括字符串,主循环,回调函数和xml解析
一.将最近用到的glib字符串功能整理了下直接用程序记录比较好看懂 #define MAX_LEN 100gchar * demo (char* msg, ...){ gchar * pcfgf ...
- 非常简单的XML解析(SAX解析、pull解析)
这里只是把解析的数据当日志打出来了 非常简单的xml解析方式 package com.example.demo.service; import java.io.IOException; import ...
- iOS-Gdata XML解析配置和简单使用
简单介绍使用废话少说直接上图就能看明白... 导入libxml2,使用第三方AFNetworking网络请求,第三方XML解析GData GData需要的配置 Build Settings 里搜索,添 ...
- 单例模式、简单工厂模式、XML解析
单例模式: 什么是单例模式? 针对特定问题提出的特定解决方案 为什么使用设计模式? 让程序有更好的可扩展性 在哪里使用? 一般情况下,开发中真正使用设计模式的地方,JVM(虚拟机)底层机制模式 usi ...
- 史上最最靠谱,又双叒叒简单的基于MSXML的XML解析指南-C++
目录 史上最最靠谱,又双叒叒简单的基于MSXML的XML解析指南 流程设计 xml信息有哪几种读取形式(xml文件或wchar) 如何选取节点,and取节点属性有哪些方法? IXMLDOMNode与I ...
- Gdata XML解析配置和简单使用
导入libxml2,使用第三方AFNetworking网络请求,第三方XML解析GData GData需要的配置 Build Settings 里搜索,添加如下
- 关于XML解析中的CDATA的简单介绍
所有 XML 文档中的文本均会被解析器解析. 只有 CDATA 区段(CDATA section)中的文本会被解析器忽略. PCDATA PCDATA 指的是被解析的字符数据(Parsed Chara ...
- xml解析技术
本文总结Dom,sax解析, 使用Java作为工具解析xml文档. 1 Dom 综述:Dom解析xml通常也称为xmlDom (和htmlDom技术差不多),将xml文档封装成树,好处就是xml中的 ...
- JSON解析和XML解析对比
JSON解析和XML解析是较为普遍的两种解析方式,其中JSON解析的市场分额更大.本文系统的分析两种解析方式的区别,为更好地处理数据作准备.由于目前阶段主要是做移动开发,所以本文所描述的JSON解析和 ...
随机推荐
- C#多任务并行阶段控制—— Threading.Barrier
有一种场景:4个人同时做某项任务,该任务分为3个阶段,必须要4个人都完成第一阶段后才可以进入第二阶段,都完成第二阶段后才可以进入第三阶段. 此时就需要对多个并行的任务做进度控制. Threading. ...
- ARC内存管理机制详解
ARC在OC里面个人感觉又是一个高大上的牛词,在前面Objective-C中的内存管理部分提到了ARC内存管理机制,ARC是Automatic Reference Counting---自动引用计数. ...
- Java多线程系列--“JUC锁”01之 框架
本章,我们介绍锁的架构:后面的章节将会对它们逐个进行分析介绍.目录如下:01. Java多线程系列--“JUC锁”01之 框架02. Java多线程系列--“JUC锁”02之 互斥锁Reentrant ...
- 解决 android 高低版本 webView 里内容 自适应屏幕的终极方法
转载请声明出处(http://www.cnblogs.com/linguanh/) 一,先说下我的情况,大家可以对号入座(嫌无聊请跳过) 我的项目要求是这样的,先从数据库里面拿出来html标签,因为加 ...
- RMAN Catalog创建、配置和管理
环境:RHEL6.4 + Oracle 11.2.0.4 一.创建数据库catdb 1.1 官档的建库脚本示例 1.2 根据我实际环境修改如下项 1.3 创建必要目录并赋予权限 1.4 执行脚本建库 ...
- Jackson的简单用法
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1简介 Jackson具有比较高的序列化和反序列化效率,据测试,无论是 ...
- 轻松搞定Win8 IIS支持SVC 从而实现IIS寄宿WCF服务
写在前面 为了尝试在IIS中寄宿WCF服务,需要配置IIS支持SVC命令,于是便有了在DOS命令中用到ServiceModelReg.exe注册svc命令. 坑爹的是注册成功后就开始报错.无奈之下两次 ...
- Android中后台的劳动者“服务”
前言 作为四大组件之一的Service,想必不少开发者都是了解的,那具体熟悉吗?是不是对Service中的每个知识点是否了解,它与Activity的关系又是什么样的,我们所理解的后台服务跟Servic ...
- sql 索引 的建立
(From:http://54laobaixing.blog.163.com/blog/static/57843681200952411133121/) 假设你想找书中的某一个句子.你可以一页一页地逐 ...
- 通过寄生组合式继承创建js的异常类
最近项目中在做js的统一的异常处理,需要自定义异常类.理想的设计方案为:自定义一个异常错误类BaseError,继承自Error,然后再自定义若干个系统异常,例如用户取消异常.表单异常.网络异常,这些 ...