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值 ...
随机推荐
- [英语学习]国外的在线广播网站,类似喜马拉雅和荔枝FM
今天在Seattle Art Museum 网站上看东西,发现了这个好网站. 主要是外文资料,可以练听力,也可以找到<我爱吕西安>的英文版本. https://soundcloud.co ...
- Hadoop2 实战系列之1 -- Hortonworks Sandbox的安装和使用
欢迎转载,转载请注明出处,谢谢,徽沪一郎. 概要 本文主要讲述如何利用hortonworks sanbox来搭建hadoop2的学习环境.Hortonworks sanbox集成了hadoop2及其上 ...
- PHP不能创建csv中文名文件
使用iconv 将utf-8转换成gb2312即可$name = iconv("utf-8","gb2312",'分销商下载课件记录');
- debug和release转载
Debug和Release区别 转自草原和大树 VC下Debug和Release区别 最近写代码过程中,发现 Debug 下运行正常,Release 下就会出现问题,百思不得其解,而Release 下 ...
- 【IOS笔记】Windows
Windows Every iOS application needs at least one window—an instance of the UIWindow class—and some m ...
- HTML: 文檔流是什麼?
[作者好人]:http://www.nowamagic.net/librarys/veda/detail/1190 文档流 将窗体自上而下分成一行行, 并在每行中按从左至右的顺序排放元素,即为文档流. ...
- pro8
1.本次课学到的知识点 函数程序设计 结构化程序设计思想 程序解析 局部变量和全局变量 2.实验过程中遇到的问题及解决方法 实验过程中会遇到自定义函数的逻辑错误 与缺少定义变量 从主函数开始理清函数关 ...
- JDK核心包学习
StringBuffer 线程安全.可变字符序列 StringBuilder 非线程安全.可变字符序列,比StringBuffer更快 Boolean 使用valueOf产生Boolean实例 ...
- 关于java字符串编译优化问题
情景一:不好的字符串拼接习惯 起因是这样的:一个大牛在写了一篇关于java字符串优化问题的讲解,他提到:不要使用strObj+otherValue的方法将otherValue转换为字符串形式,因 ...
- insert into hi_user_score set hello_id=74372073,a=10001 on duplicate key update hello_id=74372073, a=10001
insert into hi_user_score set hello_id=74372073,a=10001 on duplicate key update hello_id=74372073, a ...