//  DataModel.h
// UI1_HTTP下载
//
// Created by zhangxueming on 15/7/17.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h> @interface DataModel : NSObject @property (nonatomic, copy)NSString *name;
@property (nonatomic, assign)NSInteger downloads; @end // DataModel.m
// UI1_HTTP下载
//
// Created by zhangxueming on 15/7/17.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "DataModel.h" @implementation DataModel - (NSString *)description
{
return [NSString stringWithFormat:@"name = %@ downloads = %li", _name, _downloads];
} @end
//  AppDelegate.m
// UI1_HTTP下载
//
// Created by zhangxueming on 15/7/17.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *root = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:root];
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor];
return YES;
}
//  ViewController.h
// UI1_HTTP下载
//
// Created by zhangxueming on 15/7/17.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UITableViewController @end //
// ViewController.m
// UI1_HTTP下载
//
// Created by zhangxueming on 15/7/17.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "DataModel.h" //www.baicom.com
//http协议: 超文本传输协议 ftp://
//报文
//HttpURL格式:
//http:// 协议类型
//iappfree.candou.com 主机地址
//:8080 端口号
///free/applications/limited? 主机执行程序文件路径
//currency=rmb&page=1 主机执行程序需要的参数 每个参数之间用&隔开 @interface ViewController ()
{
NSMutableArray *_dataList;
//NSMutableData *_data;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_dataList = [NSMutableArray array]; [self loadDataWithPage:4];
} //http://iappfree.candou.com:8080/free/applications/limited?currency=rmb&page=1 //客户端 服务器 - (void)loadDataWithPage:(NSInteger)page
{
NSString *urlString = [NSString stringWithFormat:@"http://iappfree.candou.com:8080/free/applications/limited?currency=rmb&page=%ld", page]; NSURL *url = [NSURL URLWithString:urlString];
//下载数据
NSString *dataString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
//NSLog(@"dataString = %@", dataString); //转换成data
NSData *data = [dataString dataUsingEncoding:NSUTF8StringEncoding];
//json解析
id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
if ([result isKindOfClass:[NSDictionary class]]) {
//字典
NSArray *app = [result objectForKey:@"applications"];
//NSLog(@"app= %@", app);
//[_dataList addObjectsFromArray:app];
for (NSDictionary *dict in app) {
DataModel *model = [[DataModel alloc] init];
NSString *appName = [dict objectForKey:@"name"];
NSNumber *downloads = [dict objectForKey:@"downloads"];
model.name = appName;
model.downloads = [downloads integerValue];
[_dataList addObject:model];
}
NSLog(@"dataList = %@", _dataList);
}
else if([result isKindOfClass:[NSArray class]])
{
//数组 }
} #pragma mark ---UITableViewDataSource--- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _dataList.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseId = @"cellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseId];
} DataModel *model = (DataModel *)_dataList[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = model.name;
cell.detailTextLabel.text =[NSString stringWithFormat:@"下载次数:%li",model.downloads];
return cell;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

UI1_HTTP下载的更多相关文章

  1. C# ini文件操作【源码下载】

    介绍C#如何对ini文件进行读写操作,C#可以通过调用[kernel32.dll]文件中的 WritePrivateProfileString()和GetPrivateProfileString()函 ...

  2. ASP.NET Aries 入门开发教程1:框架下载与运行

    背景: 鉴于框架的使用者越来越多,文档太少,不少用户反映框架的入门门槛太高. 好吧,再辛苦下,抽时间写教程吧! 步骤1:下载框架源码 开源地址:https://github.com/cyq1162/A ...

  3. WinForm 天猫2013双11自动抢红包【源码下载】

    1. 正确获取红包流程 2. 软件介绍 2.1 效果图: 2.2 功能介绍 2.2.1 账号登录 页面开始时,会载入这个网站:https://login.taobao.com/member/login ...

  4. C# Excel导入、导出【源码下载】

    本篇主要介绍C#的Excel导入.导出. 目录 1. 介绍:描述第三方类库NPOI以及Excel结构 2. Excel导入:介绍C#如何调用NPOI进行Excel导入,包含:流程图.NOPI以及C#代 ...

  5. C# 条形码操作【源码下载】

    本篇介绍通过C#生成和读取一维码.二维码的操作. 目录 1. 介绍:介绍条形码.条形码的分类以及ZXing.Net类库. 2. 一维码操作:包含对一维码的生成.读取操作. 3. 二维码操作:包含对二维 ...

  6. mysql 7下载安装及问题解决

    mysql 7安装及问题解决 一.mysql下载 下载地址:https://www.mysql.com/downloads/ Community (GPL) Downloads MySQL Commu ...

  7. 11、Struts2 的文件上传和下载

    文件上传 表单准备 要想使用 HTML 表单上传一个或多个文件 须把 HTML 表单的 enctype 属性设置为 multipart/form-data 须把 HTML 表单的method 属性设置 ...

  8. UE4新手引导之下载和安装虚幻4游戏引擎

    1) 进入虚幻4的官方主页(https://www.unrealengine.com/) 这里你可以获得关于虚幻4的最新资讯,包括版本更新.博客更新.新闻和商城等.自2015年起,该引擎已经提供免费下 ...

  9. Windows 常用运行库下载 (DirectX、VC++、.Net Framework等)

    经常听到有朋友抱怨他的电脑运行软件或者游戏时提示缺少什么 d3dx9_xx.dll 或 msvcp71.dll.msvcr71.dll又或者是 .Net Framework 初始化之类的错误而无法正常 ...

随机推荐

  1. Java编程规范实践

    一个好的编程规范可以让代码易于理解,具体的操作却不必如此麻烦. 本文包含以下内容: Eclipse Java代码Formatter配置 Eclipse 代码模板配置 自动添加Javadoc注释 附录: ...

  2. java课堂练习之可变參数与卫条件

    /*  有人邀请A,B,C,D,E,F 6个人參加一项会议,这6个人有些奇怪.由于他们有非常多要求,已知:  1)A,B两人至少有1人參加会议:  2)A,E,F 3人中有2人參加会议.  3)B和C ...

  3. iOS开发——UI篇Swift篇&UIProgressView

    UIProgressView override func viewDidLoad() { super.viewDidLoad() titleLabel.text = titleString // Do ...

  4. MVC4数据注释与验证 2

    Using Validation Annotations Required必须项验证属性 [Required] public string FirstName { get; set; } [Requi ...

  5. JRebel_修改class后无法正确调试问题解决【2014-03-12】

    原文地址:http://www.cnblogs.com/hbbbs/p/3596179.html 现象 修改了class,编译后,JRebel自动装载到Web容器中.但此时调试这个类会发现无法正常调试 ...

  6. 【优先队列】HDU 1873——看病找医生

    来源:点击打开链接 看路径记录的BFS之前,再看一遍优先队列的用法. 优先队列的排序规则可以用运算符重载的方式完成,通常意义下,应该用friend bool operator <进行重载. #i ...

  7. 记录一次linux线上服务器被黑事件

    1.原因:本来在家正常休息了,我们放在上海托管机房的线上服务器突然蹦了远程不了,服务启动不了,然后让上海机房重启了一次,还是直接挂了,一直到我远程上才行. 2.现象:远程服务器发现出现这类信息 Hi, ...

  8. 关于设置ScrollView的滚动条为隐藏的方法

    要实现ScrollView滚动条的隐藏,有两种方法, 一种是在XML的ScrollView布局中加入属性android:scrollbars="none" 另一种则是在代码中获取S ...

  9. iOS-自定义导航栏后侧滑返回功能失效

    iPhone有一个回退按钮在所有的导航条上.这是一个简单的没有文字箭头. 在一开始写项目的时候,就要做好一个准备,导航栏是自定义还是使用系统的,后期有什么改动,有什么比较特殊的需求.当然这些在更改需求 ...

  10. 浅析jQuery中常用的元素查找方法总结

    本篇文章是对jQuery中常用的元素查找方法进行了详细的总结和介绍,需要的朋友参考下   $("#myELement") 选择id值等于myElement的元素,id值不能重复在文 ...