1. #import <UIKit/UIKit.h>
  2.  
  3. @interface AppDelegate : UIResponder <UIApplicationDelegate>
  4.  
  5. @property (strong, nonatomic) UIWindow *window;
  6.  
  7. @end
  1. #import "AppDelegate.h"
  2. #import "RootViewController.h"
  3. @interface AppDelegate ()
  4.  
  5. @end
  6.  
  7. @implementation AppDelegate
  8.  
  9. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  10. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  11. // Override point for customization after application launch.
  12. self.window.backgroundColor = [UIColor whiteColor];
  13.  
  14. self.window.rootViewController = [[RootViewController alloc] init];
  15.  
  16. [self.window makeKeyAndVisible];
  17. return YES;
  18. }
  19.  
  20. @end
  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface RootViewController : UIViewController
  4.  
  5. @end
  1. #import "RootViewController.h"
  2. #define cellWidth [UIScreen mainScreen].bounds.size.width
  3. @interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
  4. {
  5. // NSMutableArray *dateArr;
  6. NSMutableArray *timeArr;// 时间
  7. NSMutableArray *messsgeArr; // 物流信息
  8. UITableView * _tableView;
  9. }
  10. @end
  11.  
  12. @implementation RootViewController
  13.  
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. // self.view.backgroundColor = [UIColor lightGrayColor];
  17. // dateArr = [[NSMutableArray alloc] init];
  18. timeArr = [[NSMutableArray alloc] init];
  19. messsgeArr = [[NSMutableArray alloc] init];
  20.  
  21. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(, , cellWidth, [UIScreen mainScreen].bounds.size.height - ) style:UITableViewStylePlain];
  22. _tableView.delegate = self;
  23. _tableView.dataSource = self;
  24. _tableView.backgroundColor = [UIColor lightGrayColor];
  25. [self.view addSubview:_tableView];
  26. //去掉多余的cell
  27. _tableView.tableFooterView = [[UIView alloc] init];
  28.  
  29. // 请求数据并进行处理
  30. NSString *htmlString = @"http://wap.kuaidi100.com/wap_result.jsp?rand=20120517&id=zhongtong&fromWeb=null&&postid=718969747957";
  31. // NSString *htmlString = @"http://wap.kuaidi100.com/wap_result.jsp?rand=20120517&id=shentong&fromWeb=null&&postid=718969747957";
  32.  
  33. // NSString *htmlString = @"http://wap.kuaidi100.com/wap_result.jsp?rand=20120517&id=shenong&fromWeb=null&&postid=78969747957";
  34. [self dealWithExpressMessage:htmlString];
  35. }
  36.  
  37. - (void)dealWithExpressMessage:(NSString*)htmlString{
  38.  
  39. NSString *dataString = [NSString stringWithContentsOfURL:[NSURL URLWithString:htmlString] encoding:NSUTF8StringEncoding error:nil];
  40. NSData *htmlData = [dataString dataUsingEncoding:NSUTF8StringEncoding];
  41.  
  42. NSString *string = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
  43. // NSLog(@"************%@",string);
  44. // 判断链接是否出错
  45. NSArray *linkError = [string componentsSeparatedByString:@"404错误"];
  46. if (linkError.count > ) {
  47. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"信息有误" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
  48. [alertView show];
  49. return;
  50. }
  51. // 判断快递的信息是否有误,是则提示
  52. NSArray *isError = [string componentsSeparatedByString:@"我要报错"];
  53. if (isError.count == ) {
  54. NSLog(@"======");
  55. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"信息有误" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
  56. [alertView show];
  57. return;
  58. }
  59.  
  60. // 获取快递信息
  61. NSArray * array = [string componentsSeparatedByString:@"<p>&middot"];
  62. // 分割后,获取有用的信息
  63. NSMutableArray *mArr = [[NSMutableArray alloc] init];
  64. for (int i = ; i < array.count; i++ ) {
  65. if ((i != ) && (i != array.count - )) {
  66. [mArr addObject:array[i]];
  67. }
  68. if (i == array.count -) {
  69. NSArray *newArr = [array[i] componentsSeparatedByString:@"</form>"];
  70. NSString *string = newArr[];
  71. [mArr addObject:string];
  72. }
  73. }
  74. // 将获取到的数据分开
  75. for (NSString *subString in mArr) {
  76.  
  77. NSArray *array = [subString componentsSeparatedByString:@"<br />"];
  78. NSString *timeString = array[];
  79. NSArray *dateArray = [timeString componentsSeparatedByString:@";"];
  80. [timeArr addObject:dateArray[]];
  81. /* 将年月日与时分秒的时间分开
  82. NSArray *spaTimeArr = [timeString componentsSeparatedByString:@" "];
  83. NSArray *dateArray = [spaTimeArr[0] componentsSeparatedByString:@";"];
  84. // 获取年月日的时间
  85. [dateArr addObject:dateArray[1]];
  86. //获取时分秒的时间
  87. [timeArr addObject:spaTimeArr[1]];
  88. */
  89. // NSLog(@" == %@",dateArray[1]);
  90.  
  91. NSString *address = array[];
  92. NSArray *addressArr = [address componentsSeparatedByString:@"</p>"];
  93. // 存放快递的信息
  94. NSString *newString = [addressArr[] stringByReplacingOccurrencesOfString:@" " withString:@""];
  95. [messsgeArr addObject:newString];
  96. // NSLog(@"==%@",newString);
  97. }
  98. // NSLog(@"===== %@",messsgeArr);
  99. }
  100.  
  101. #pragma mark -- tableView 的数据配置 --
  102. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  103. return ;
  104. }
  105. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  106. return timeArr.count;
  107. }
  108.  
  109. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  110. {
  111. UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
  112. return cell.frame.size.height;
  113. }
  114.  
  115. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  116.  
  117. static NSString *identifier = @"cell";
  118. tableView.separatorStyle = UITableViewCellSelectionStyleNone;
  119. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  120. if (cell == nil) {
  121. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  122. }
  123. cell.userInteractionEnabled = NO;
  124. for (UIView *subView in cell.subviews) {
  125. [subView removeFromSuperview];
  126. }
  127. cell.backgroundColor = [UIColor lightGrayColor];
  128. UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , cellWidth, )];
  129. timeLabel.textColor = [UIColor blueColor];
  130. timeLabel.font = [UIFont systemFontOfSize:];
  131. timeLabel.backgroundColor = [UIColor clearColor];
  132. [cell addSubview:timeLabel];
  133. timeLabel.text = timeArr[indexPath.row];
  134.  
  135. UILabel *messageLabel = [[UILabel alloc] init];
  136. [cell addSubview:messageLabel];
  137. messageLabel.text = messsgeArr[indexPath.row];
  138.  
  139. messageLabel.numberOfLines = ;
  140. messageLabel.backgroundColor = [UIColor clearColor];
  141. messageLabel.textColor = [UIColor blackColor];
  142. UIFont *font = [UIFont fontWithName:@"Arial" size:];
  143. messageLabel.font = font;
  144. CGSize constraint = CGSizeMake(cellWidth - , );
  145. CGSize size = [messageLabel.text sizeWithFont:font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
  146. // CGSize labelSize = [messageLabel.text boundingRectWithSize:boundSize options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil].size;
  147. messageLabel.frame = CGRectMake(, , size.width,size.height);
  148. CGRect rect = cell.frame;
  149. rect.size.height = timeLabel.frame.size.height + messageLabel.frame.size.height + ;
  150. cell.frame = rect;
  151.  
  152. return cell;
  153. }
  154.  
  155. @end

iOS 快递查询的更多相关文章

  1. 快递查询SDK

    简介: 快递查询的SDK,使用的是快递100的智能查询,此SDK只是中间包装了一层而已,单对于普通的快递业务查询已经足够,也省去开发者研究的时间,拿来即用. 用途: 1.对接微信公众平台 2.对接需要 ...

  2. Windows Phone7 快递查询

        (1)API去友商100里申请 布局代码: Exp.xaml <phone:PhoneApplicationPage x:Class="WindowsPhone_Express ...

  3. baidu 快递查询API

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  4. 快递查询API接口(trackingmore)

    快递查询接口 目前提供快递查询的接口平台有: Trackingmore 快递100 快递网 不同接口的区别: (1)Trackingmore支持380家快递公司,其中有55家为国内的快递,其余325家 ...

  5. 常用免费快递查询API对接案例

    现在许多电商公司和ERP都会寻找比较适用的集成快递查询接口,减少对接难度,现在整理一下常用的免费快递查询接口,并附上调用案例,如果有觉得不对的地方,望能够一起沟通探讨! 一.快递查询接口 目前有提供免 ...

  6. 快递查询API接口对接方法

    各类接口 快递查询API有即时查询和订阅查询两种,即时是请求即返回数据,订阅则是订阅快递单号到接口,有物流轨迹更新则全量返回数据.目前常用的有快递鸟.快递100.快递网等. 快递鸟即时API可以查询3 ...

  7. 快递查询api(多接口方案)

    /** 本环境使用php+smarty,结合两种快递api调取快递数据 * 说明,先快递鸟调取数据,失败后再调取快递网的数据* 快递鸟 http://www.kdniao.com 快递网 http:/ ...

  8. 各种快递查询--Api接口

    授权成功我的密钥 爱查快递API使用说明文档 API地址: 以前:http://api.ickd.cn/?com=[]&nu=[]&id=[]&type=[]&enco ...

  9. Android项目---快递查询

    快递查询,快递100上有更多接口信息 1.快递查询的接口是 快递公司的code值+快递单号 进行的网络查询.第一步,怎么将快递公司的名字转换成code值,传递给接口.下面是快递公司以及对应的code值 ...

随机推荐

  1. Apache Spark源码走读之2 -- Job的提交与运行

    欢迎转载,转载请注明出处,徽沪一郎. 概要 本文以wordCount为例,详细说明spark创建和运行job的过程,重点是在进程及线程的创建. 实验环境搭建 在进行后续操作前,确保下列条件已满足. 下 ...

  2. php 递归创建目录、递归删除非空目录、迭代创建目录

    递归创建目录 方法一 function mk_dir($path){ if(is_dir($path)){ //参数本身是一个目录 return true; } if(is_dir(dirname($ ...

  3. 浏览器User-agent String里的历史故事

    你是否好奇标识浏览器身份的User-Agent,为什么每个浏览器都有Mozilla字样? Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 ...

  4. 使用CodeIgniter框架搭建RESTful API服务

    使用CodeIgniter框架搭建RESTful API服务 发表于 2014-07-12   |   分类于 翻译笔记   |   6条评论 在2011年8月的时候,我写了一篇博客<使用Cod ...

  5. 尝试使用word发布博客

    尝试使用WORD2010发布博客   使用博客园博客的主要原因在于能够使用live writer,不用每次都打开网页,当然博客园的大牛很多   如果可以使用方法word,当让更爽,格式的问题将不再是问 ...

  6. Apache服务器安装配置

    Apache服务器安装 1.Apache服务器安装      在Linux系统下,apache服务器的安装方式比较灵活,可以使用二进制包安装,比如:rpm包.deb包.已编译好的包.也可以简单的使用y ...

  7. mysql 锁

    Lock table有两种模式 lock tables table_name  read  [or write]; test1: session 1: lock tables tmp_xf_lock; ...

  8. functional cohesion

    Computer Science An Overview _J. Glenn Brookshear _11th Edition A weak form of cohesion is known as ...

  9. php经典笔试题

    五.基础及程序题(建议使用你擅长的语言:C/C++.PHP.Java) 5.写一个排序算法,可以是冒泡排序或者是快速排序,假设待排序对象是一个维数组.(提示:不能使用系统已有函数,另外请仔细回忆以前学 ...

  10. FW:使用weave管理docker网络

    Posted on 2014-11-12 22:20 feisky 阅读(1761) 评论(0) 编辑 收藏 weave简介 Weave creates a virtual network that ...