#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>&middot"];
// 分割后,获取有用的信息
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 快递查询的更多相关文章

  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. python twisted启动定时服务

    以下是python脚本send_mms.py #############################################!/usr/bin/python# -*- coding: ut ...

  2. 【HAPPY FOREST】用Unreal Engine4绘制实时CG影像

    用Unreal Engine绘制实时CG影像 近年来,对实时CG的关心热度越来越高,但要想弥补与预渲染方式的差异并不是那么容易.这里就有影像业界的先锋进行挑战的MARZA ANIMATION PLAN ...

  3. Vi问题

    ,ubuntu11.10下vi编辑器按i,左下方没有出现“输入模式”或者“insert”.在桌面环境下,用ctrl+alt+t调出命令行打开是这样,在第一控制台ctrl+alt+F1下打开,也是这样, ...

  4. apache的prefork的详解

    apache的prefork的参数详解:ServerLimit 2000 这是最大进程数的阀值StartServers 25  启动时建立的子进程MinSpareServers 25 最小空闲进程Ma ...

  5. SQL控制语句中内置函数讲解

    一.伪表.系统内置的只有一行一列数据的表.常用来执行函数. select 函数名 from dual 注:以下所有函数为了方便理解均用 伪表 做为事例! 二. 时间函数 1.sysdate:获取数据库 ...

  6. ASP.NET一些公共方法commTools

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  7. 20145319 《java程序设计》课程总结

    20145319 <Java程序设计>课程总结 读书笔记链接总结 - 20145319 第一周学习总结 - 20145319 第二周学习总结 - 20145319 第三周学习总结 - 20 ...

  8. 【Android测试】【随笔】搜狗、腾讯技术交流会心得

    ◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5048525.html 今天没上班,一大早就起来赶去搜狐网络 ...

  9. zepto源码--filtered, contains,funcArg,setAttribute,className,deserializeVale--学习笔记

    几个方法 1.filtered 目标是对节点按照一定的选择器进行过滤. 如果传入了过滤选择器,则在nodes节点下,选择符合选择器的节点: 如果没有传入选择器,则返回节点本身,转化为zepto节点. ...

  10. Bundle文件的创建和使用(二)

    1.概念: An NSBundle object represents a location in the file system that groups code and resources tha ...