//  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. IPC——共享内存

    Linux进程间通信——使用共享内存 下面将讲解进程间通信的另一种方式,使用共享内存.   一.什么是共享内存 顾名思义,共享内存就是允许两个不相关的进程访问同一个逻辑内存.共享内存是在两个正在运行的 ...

  2. iOS开发,hook系统Objective-C的函数

    我们都知道在windows下可以通过API轻松的hook很多消息,IOS也可以实现hook的功能. 建立一个 TestHookObject类 // // TestHookObject.m // Tes ...

  3. 向linux内核版本号添加字符/为何有时会自动添加“+”号

    转载:http://blog.csdn.net/adaptiver/article/details/7225980 1.   引子 编译2.6.35.7 kernel版本的时候发现,“2.6.35.7 ...

  4. The Socket API, Part 3: Concurrent Servers

    转:http://www.linuxforu.com/2011/10/socket-api-part-3-concurrent-servers/ By Pankaj Tanwar on October ...

  5. 利用js、css、html固定table的列头不动

    1.CSS <style type="text/css"> #scroll_head { position: absolute; display: none; } &l ...

  6. maven添加jetty插件

    pom.xml中增加jetty的配置 <properties> <jetty-version>8.1.13.v20130916</jetty-version> &l ...

  7. java中的链式编程

    听到链式编程听陌生的,但是写出来就感觉其实很熟悉 package test; public class Test { String name; String phone; String mail; S ...

  8. 最近在用placeholder ,是已有的,网上也有不少都是jq写的

    其实除了支持placeholder 的浏览器,其他用js 或jq实现的都不叫placeholder 效果,只能算上是获取焦点,或失去焦点时的一个placeholder 没有出生时就已经存在效果 很多人 ...

  9. 用英文加优先级来解读C的声明

    比如:int ( * func_p ) ( double ); 首先着眼于标识符. func_p is 因为存在括号,(* func_p) 先被处理,这里着眼于* func_p is a pointe ...

  10. 《MFC游戏开发》笔记五 定时器和简单动画

    本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9332377 作者:七十一雾央 新浪微博:http:// ...