//  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. vs2013 设置为中文版

  2. oc-14-对象方法调用类方法

    Person.h #import <Foundation/Foundation.h> @interface Person : NSObject { @public int _age; fl ...

  3. 云服务器 ECS Linux 系统 CPU 占用率较高问题排查思路

    https://help.aliyun.com/knowledge_detail/41225.html?spm=5176.7841174.2.2.ifP9Sc 注意:本文相关配置及说明已在 CentO ...

  4. Ogre Addon之Paged Geometry

    还是OGRE好啊,无尽的Addon,无尽的宝藏.既有SkyX,Hydrx这样的天空水体渲染库可供学习,还有Paged Geometry这样的“大规模海量geometry管理系统”.它通过batch,s ...

  5. NHibernate讲解

    第1章 NHibernate体系结构 总览 对NHibernate体系结构的非常高层的概览: 这幅图展示了NHibernate使用数据库和配置文件数据来为应用程序提供持久化服务(和持久化的对象). 我 ...

  6. PHP|开发必知的良好实践

    过滤.验证.转义 所有这些外部资源都不能完全相信 $_GET $_POST $_REQUEST $_COOKIE $argv php://stdin php://input file_get_cont ...

  7. Java再学习——Executor,ExecutorService,ScheduledExecutorService与Executors

    1,Executor.ExecutorService和ScheduledExecutorService,它们都是接口,它们的关系是ScheduledExecutorService继承ExecutorS ...

  8. Socket 之 同步以及异步通信

    用netstat侦听下端口状态 同步通信: 预定义结构体,同步通信没有多线程异步委托回调,所以无需预定义结构体 客户端Client: class Program { static void Main( ...

  9. Windows OpenVPN Client and tls-auth

    The official Windows OpenVPN client does not seem to work properly with the tls-auth option if a key ...

  10. Oracle安装步骤及PL/SQL Developer连接数据库

    一:Oracle安装步骤及PL/SQL Developer连接数据库 win7 64位 11g 点击(操作步骤):http://www.cnblogs.com/haoke/articles/27343 ...