iOS 快递查询
- #import <UIKit/UIKit.h>
- @interface AppDelegate : UIResponder <UIApplicationDelegate>
- @property (strong, nonatomic) UIWindow *window;
- @end
- #import "AppDelegate.h"
- #import "RootViewController.h"
- @interface AppDelegate ()
- @end
- @implementation AppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // Override point for customization after application launch.
- self.window.backgroundColor = [UIColor whiteColor];
- self.window.rootViewController = [[RootViewController alloc] init];
- [self.window makeKeyAndVisible];
- return YES;
- }
- @end
- #import <UIKit/UIKit.h>
- @interface RootViewController : UIViewController
- @end
- #import "RootViewController.h"
- #define cellWidth [UIScreen mainScreen].bounds.size.width
- @interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
- {
- // NSMutableArray *dateArr;
- NSMutableArray *timeArr;// 时间
- NSMutableArray *messsgeArr; // 物流信息
- UITableView * _tableView;
- }
- @end
- @implementation RootViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // self.view.backgroundColor = [UIColor lightGrayColor];
- // dateArr = [[NSMutableArray alloc] init];
- timeArr = [[NSMutableArray alloc] init];
- messsgeArr = [[NSMutableArray alloc] init];
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(, , cellWidth, [UIScreen mainScreen].bounds.size.height - ) style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.backgroundColor = [UIColor lightGrayColor];
- [self.view addSubview:_tableView];
- //去掉多余的cell
- _tableView.tableFooterView = [[UIView alloc] init];
- // 请求数据并进行处理
- NSString *htmlString = @"http://wap.kuaidi100.com/wap_result.jsp?rand=20120517&id=zhongtong&fromWeb=null&&postid=718969747957";
- // NSString *htmlString = @"http://wap.kuaidi100.com/wap_result.jsp?rand=20120517&id=shentong&fromWeb=null&&postid=718969747957";
- // NSString *htmlString = @"http://wap.kuaidi100.com/wap_result.jsp?rand=20120517&id=shenong&fromWeb=null&&postid=78969747957";
- [self dealWithExpressMessage:htmlString];
- }
- - (void)dealWithExpressMessage:(NSString*)htmlString{
- NSString *dataString = [NSString stringWithContentsOfURL:[NSURL URLWithString:htmlString] encoding:NSUTF8StringEncoding error:nil];
- NSData *htmlData = [dataString dataUsingEncoding:NSUTF8StringEncoding];
- NSString *string = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
- // NSLog(@"************%@",string);
- // 判断链接是否出错
- NSArray *linkError = [string componentsSeparatedByString:@"404错误"];
- if (linkError.count > ) {
- UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"信息有误" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
- [alertView show];
- return;
- }
- // 判断快递的信息是否有误,是则提示
- NSArray *isError = [string componentsSeparatedByString:@"我要报错"];
- if (isError.count == ) {
- NSLog(@"======");
- UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"信息有误" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
- [alertView show];
- return;
- }
- // 获取快递信息
- NSArray * array = [string componentsSeparatedByString:@"<p>·"];
- // 分割后,获取有用的信息
- NSMutableArray *mArr = [[NSMutableArray alloc] init];
- for (int i = ; i < array.count; i++ ) {
- if ((i != ) && (i != array.count - )) {
- [mArr addObject:array[i]];
- }
- if (i == array.count -) {
- NSArray *newArr = [array[i] componentsSeparatedByString:@"</form>"];
- NSString *string = newArr[];
- [mArr addObject:string];
- }
- }
- // 将获取到的数据分开
- for (NSString *subString in mArr) {
- NSArray *array = [subString componentsSeparatedByString:@"<br />"];
- NSString *timeString = array[];
- NSArray *dateArray = [timeString componentsSeparatedByString:@";"];
- [timeArr addObject:dateArray[]];
- /* 将年月日与时分秒的时间分开
- NSArray *spaTimeArr = [timeString componentsSeparatedByString:@" "];
- NSArray *dateArray = [spaTimeArr[0] componentsSeparatedByString:@";"];
- // 获取年月日的时间
- [dateArr addObject:dateArray[1]];
- //获取时分秒的时间
- [timeArr addObject:spaTimeArr[1]];
- */
- // NSLog(@" == %@",dateArray[1]);
- NSString *address = array[];
- NSArray *addressArr = [address componentsSeparatedByString:@"</p>"];
- // 存放快递的信息
- NSString *newString = [addressArr[] stringByReplacingOccurrencesOfString:@" " withString:@""];
- [messsgeArr addObject:newString];
- // NSLog(@"==%@",newString);
- }
- // NSLog(@"===== %@",messsgeArr);
- }
- #pragma mark -- tableView 的数据配置 --
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return ;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return timeArr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
- return cell.frame.size.height;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *identifier = @"cell";
- tableView.separatorStyle = UITableViewCellSelectionStyleNone;
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
- }
- cell.userInteractionEnabled = NO;
- for (UIView *subView in cell.subviews) {
- [subView removeFromSuperview];
- }
- cell.backgroundColor = [UIColor lightGrayColor];
- UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , cellWidth, )];
- timeLabel.textColor = [UIColor blueColor];
- timeLabel.font = [UIFont systemFontOfSize:];
- timeLabel.backgroundColor = [UIColor clearColor];
- [cell addSubview:timeLabel];
- timeLabel.text = timeArr[indexPath.row];
- UILabel *messageLabel = [[UILabel alloc] init];
- [cell addSubview:messageLabel];
- messageLabel.text = messsgeArr[indexPath.row];
- messageLabel.numberOfLines = ;
- messageLabel.backgroundColor = [UIColor clearColor];
- messageLabel.textColor = [UIColor blackColor];
- UIFont *font = [UIFont fontWithName:@"Arial" size:];
- messageLabel.font = font;
- CGSize constraint = CGSizeMake(cellWidth - , );
- CGSize size = [messageLabel.text sizeWithFont:font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
- // CGSize labelSize = [messageLabel.text boundingRectWithSize:boundSize options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil].size;
- messageLabel.frame = CGRectMake(, , size.width,size.height);
- CGRect rect = cell.frame;
- rect.size.height = timeLabel.frame.size.height + messageLabel.frame.size.height + ;
- cell.frame = rect;
- return cell;
- }
- @end
iOS 快递查询的更多相关文章
- 快递查询SDK
简介: 快递查询的SDK,使用的是快递100的智能查询,此SDK只是中间包装了一层而已,单对于普通的快递业务查询已经足够,也省去开发者研究的时间,拿来即用. 用途: 1.对接微信公众平台 2.对接需要 ...
- Windows Phone7 快递查询
(1)API去友商100里申请 布局代码: Exp.xaml <phone:PhoneApplicationPage x:Class="WindowsPhone_Express ...
- baidu 快递查询API
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 快递查询API接口(trackingmore)
快递查询接口 目前提供快递查询的接口平台有: Trackingmore 快递100 快递网 不同接口的区别: (1)Trackingmore支持380家快递公司,其中有55家为国内的快递,其余325家 ...
- 常用免费快递查询API对接案例
现在许多电商公司和ERP都会寻找比较适用的集成快递查询接口,减少对接难度,现在整理一下常用的免费快递查询接口,并附上调用案例,如果有觉得不对的地方,望能够一起沟通探讨! 一.快递查询接口 目前有提供免 ...
- 快递查询API接口对接方法
各类接口 快递查询API有即时查询和订阅查询两种,即时是请求即返回数据,订阅则是订阅快递单号到接口,有物流轨迹更新则全量返回数据.目前常用的有快递鸟.快递100.快递网等. 快递鸟即时API可以查询3 ...
- 快递查询api(多接口方案)
/** 本环境使用php+smarty,结合两种快递api调取快递数据 * 说明,先快递鸟调取数据,失败后再调取快递网的数据* 快递鸟 http://www.kdniao.com 快递网 http:/ ...
- 各种快递查询--Api接口
授权成功我的密钥 爱查快递API使用说明文档 API地址: 以前:http://api.ickd.cn/?com=[]&nu=[]&id=[]&type=[]&enco ...
- Android项目---快递查询
快递查询,快递100上有更多接口信息 1.快递查询的接口是 快递公司的code值+快递单号 进行的网络查询.第一步,怎么将快递公司的名字转换成code值,传递给接口.下面是快递公司以及对应的code值 ...
随机推荐
- Apache Spark源码走读之2 -- Job的提交与运行
欢迎转载,转载请注明出处,徽沪一郎. 概要 本文以wordCount为例,详细说明spark创建和运行job的过程,重点是在进程及线程的创建. 实验环境搭建 在进行后续操作前,确保下列条件已满足. 下 ...
- php 递归创建目录、递归删除非空目录、迭代创建目录
递归创建目录 方法一 function mk_dir($path){ if(is_dir($path)){ //参数本身是一个目录 return true; } if(is_dir(dirname($ ...
- 浏览器User-agent String里的历史故事
你是否好奇标识浏览器身份的User-Agent,为什么每个浏览器都有Mozilla字样? Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 ...
- 使用CodeIgniter框架搭建RESTful API服务
使用CodeIgniter框架搭建RESTful API服务 发表于 2014-07-12 | 分类于 翻译笔记 | 6条评论 在2011年8月的时候,我写了一篇博客<使用Cod ...
- 尝试使用word发布博客
尝试使用WORD2010发布博客 使用博客园博客的主要原因在于能够使用live writer,不用每次都打开网页,当然博客园的大牛很多 如果可以使用方法word,当让更爽,格式的问题将不再是问 ...
- Apache服务器安装配置
Apache服务器安装 1.Apache服务器安装 在Linux系统下,apache服务器的安装方式比较灵活,可以使用二进制包安装,比如:rpm包.deb包.已编译好的包.也可以简单的使用y ...
- mysql 锁
Lock table有两种模式 lock tables table_name read [or write]; test1: session 1: lock tables tmp_xf_lock; ...
- functional cohesion
Computer Science An Overview _J. Glenn Brookshear _11th Edition A weak form of cohesion is known as ...
- php经典笔试题
五.基础及程序题(建议使用你擅长的语言:C/C++.PHP.Java) 5.写一个排序算法,可以是冒泡排序或者是快速排序,假设待排序对象是一个维数组.(提示:不能使用系统已有函数,另外请仔细回忆以前学 ...
- FW:使用weave管理docker网络
Posted on 2014-11-12 22:20 feisky 阅读(1761) 评论(0) 编辑 收藏 weave简介 Weave creates a virtual network that ...