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解析和 ...
随机推荐
- 把DATATABLE,DS中的内容用HTML的方式显示
前几天,在搞一个数据显示的时候,因为是不固定的列的,所以需要动态创建列,这里面就运用一下,直接把数据库的Table显示在Html上,有两种方法,但是都有相应的缺点,第一个,如果内容太多,长度不好控制, ...
- codefordream 关于js中级训练
中级训练接着就紧锣密鼓的开始了. 首先是关于变量,变量的作用是给一个数据值标注名称. 注:JavaScript中变量名,函数名,参数名的命名规范:至少由字母,下划线,美元符号,数字其中的一种组成,但不 ...
- Java:IDEA下使用JUNIT
JUnit单元测试--IntelliJ IDEA (本文转载自华行天下) 单元测试的基本使用 一.环境配置 使用idea IDE 进行单元测试,首先需要安装JUnit 插件. 1.安装JUnit插件步 ...
- 相克军_Oracle体系_随堂笔记003-体系概述
1.进程结构图 对Oracle生产库来讲,服务器进程(可以简单理解是前台进程)的数量远远大于后台进程.因为一个用户进程对应了一个服务器进程. 而且后台进程一般出问题几率不大,所以学习重点也是服务器进程 ...
- Hibernate —— 检索策略
一.Hibernate 的检索策略本质上是为了优化 Hibernate 性能. 二.Hibernate 检索策略包括类级别的检索策略.和关联级别的检索策略(<set> 元素) 三.类级别的 ...
- 重构sql server的sys.sp_helptext存储
本文目录列表: 1.sys.sp_helptext存储的功能和效果 2.重构sys.sp_helptext存储(命名为dbo.usp_helptext)提供直观的效果 3.sys.sp_helptex ...
- JS产生随机数的几个用法!
<script> function GetRandomNum(Min,Max) { var Range = Max - Min; var Rand = Math.random(); ret ...
- Web 分页
以Car表为例分页 页面以table展示数据分页 页面代码 <asp:Repeater ID="Repeater1" runat="server"> ...
- 浅谈 C#委托
看了<CLR via C#>的17章委托后,为自己做一点浅显的总结,也分享给需要的人. .NET通过委托来提供一种回调函数机制,.NET委托提供了很多功能,例如确保回调方法是类型安全的(C ...
- html5 前端图片处理(预览、压缩、缩放)
现在手机图片是越来越大了,上传图片流量耗费巨大.同时预览也是一个问题,所以利用HTML5 file和canvas来解决这个问题. var upload = { _o: null,//对象id _aut ...