//  HttpManager.h
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// #import <Foundation/Foundation.h>
#import "AFNetworking.h"
typedef void (^sucessBlock)(AFHTTPRequestOperation *operation, id responseObject);
typedef void (^faileBlock)(AFHTTPRequestOperation *operation, NSError *error);
@interface HttpManager : NSObject + (HttpManager *)shareManager;
- (void)requestWithUrl:(NSString *)url withDic:(NSDictionary *)dic WithSuccess:(sucessBlock)sucBlock WithFailure:(faileBlock) failBlock;
@end //
// HttpManager.m
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// #import "HttpManager.h" @implementation HttpManager + (HttpManager *)shareManager
{
static HttpManager *manager;
static dispatch_once_t once;
dispatch_once(&once,^{ if(manager ==nil)
{
manager =[[HttpManager alloc]init];
} });
return manager; // static dispatch_once_t *once; 错误
// dispatch_once(once,^{ } - (void)requestWithUrl:(NSString *)url withDic:(NSDictionary *)dic WithSuccess:(sucessBlock)sucBlock WithFailure:(faileBlock) failBlock {
AFHTTPRequestOperationManager *manager =[AFHTTPRequestOperationManager manager]; //manager.responseSerializer.acceptableContentTypes =[NSSet setWithObject:@"application/json"]; manager.responseSerializer.acceptableContentTypes =[NSSet setWithObjects:@"application/json",@"text/text", nil];
[manager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
sucBlock(operation,responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error:%@",error);
failBlock(operation,error); }];
}
@end
//
// GFControl.h
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface GFControl : NSObject
+ (UILabel *)createLabelWithFrame:(CGRect)frame WithFont:(UIFont *)font;
@end //
// GFControl.m
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// #import "GFControl.h" @implementation GFControl + (UILabel *)createLabelWithFrame:(CGRect)frame WithFont:(UIFont *)font
{
UILabel *label =[[UILabel alloc]initWithFrame:frame];
label.textColor=[UIColor blackColor];
label.font=font;
label.textAlignment=NSTextAlignmentLeft;
return label;
}
@end
//
// MyModel.h
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// #import "JSONModel.h" //创建的时候继承至JSONModel
//#import "JSONModelLib.h" //@protocol CreateDateModel
//@end
@protocol ObjModel
@end @interface CreateDateModel : JSONModel @property (nonatomic,strong) NSString <Optional> *date;
@property (nonatomic,strong) NSString <Optional> *day;
@property (nonatomic,strong) NSString <Optional> *hours;
@property (nonatomic,strong) NSString <Optional> *minutes;
@property (nonatomic,strong) NSString <Optional> *month;
@property (nonatomic,strong) NSString <Optional> *seconds;
@property (nonatomic,strong) NSString <Optional> *time;
@property (nonatomic,strong) NSString <Optional> *timezoneOffset;
@property (nonatomic,strong) NSString <Optional> *year;
@end @interface ObjModel : JSONModel @property (nonatomic,strong) NSString <Optional> *descriptionOne;
@property (nonatomic,strong) NSString <Optional> *isNew;
@property (nonatomic,strong) NSString <Optional> *isRecommend;
@property (nonatomic,strong) NSString <Optional> *isSubscibe;
@property (nonatomic,strong) NSString <Optional> *itemID;
@property (nonatomic,strong) NSString <Optional> *itemName;
@property (nonatomic,strong) NSString <Optional> *picUrl;
@property (nonatomic,strong) NSString <Optional> *readNum;
//@property (nonatomic,strong) NSString <Optional> *numRows;
//@property (nonatomic,strong) NSArray <Optional,CreateDateModel> *obj; @property (nonatomic,strong) CreateDateModel <Optional> *createDate;
@end @interface MyModel : JSONModel @property (nonatomic,strong) NSString <Optional> *numRows;
@property (nonatomic,strong) NSDictionary <Optional> *resultObj;
@property (nonatomic,strong) NSArray <Optional,ObjModel> *obj;
@end //
// MyModel.m
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// #import "MyModel.h" @implementation CreateDateModel @end @implementation ObjModel +(JSONKeyMapper *)keyMapper
{
// NSMutableDictionary *dic =[[NSMutableDictionary alloc]init];
// [dic setObject:@"description" forKey:@"description1"];
// return [[JSONKeyMapper alloc]initWithDictionary:dic]; return [[JSONKeyMapper alloc]initWithDictionary:@{@"description":@"descriptionOne"}];
} @end @implementation MyModel @end
//  MyCell.h
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface MyCell : UITableViewCell @property (nonatomic,strong)UILabel *itemNameLabel;
@property (nonatomic,strong)UILabel *desLabel;
@property (nonatomic,strong)UILabel *timeLabel;
@property (nonatomic,strong)UIImageView *psImage; @end //
// MyCell.m
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// #import "MyCell.h"
#import "GFControl.h"
@implementation MyCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self configCell];
} return self;
} - (void)configCell
{
_psImage =[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 80, 90)];
[self addSubview:_psImage]; CGFloat witdth=[[UIScreen mainScreen] bounds].size.width; _itemNameLabel =[GFControl createLabelWithFrame:CGRectMake(110, 10, witdth-100-10, 30) WithFont:[UIFont systemFontOfSize:15]];
// NSLog(@"%@",_itemNameLabel.text); [self addSubview:_itemNameLabel]; _desLabel =[GFControl createLabelWithFrame:CGRectMake(110, 40, witdth-100-10, 30) WithFont:[UIFont systemFontOfSize:13]];
[self addSubview:_desLabel]; _timeLabel =[GFControl createLabelWithFrame:CGRectMake(110, 70, witdth-100-10, 30) WithFont:[UIFont systemFontOfSize:13]];
_timeLabel.textAlignment=NSTextAlignmentRight;
[self addSubview:_timeLabel];
}
@end
//  ViewController.h
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end //
// ViewController.m
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// #import "ViewController.h"
#import "HttpManager.h"
#import "MyModel.h"
#import "MyCell.h"
#import "UIImageView+WebCache.h"
#define KPostUrl @"http://services.baidu.com/ApricotForestWirelessServiceForLiterature/LiteratureDataServlet"
@interface ViewController () <UITableViewDataSource,UITableViewDelegate>
{
MyModel *_myModel;
UITableView *_tabelView;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // self.view.backgroundColor=[UIColor whiteColor];
//
// [[HttpManager shareManager] requestWithUrl:@"" withDic:nil WithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//
// } WithFailure:^(AFHTTPRequestOperation *operation, NSError *error) {
//
// }];
[self configUI];
[self requestdata]; } - (void)configUI
{
_tabelView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:_tabelView];
_tabelView.delegate=self;
_tabelView.dataSource=self; [_tabelView registerClass:[MyCell class] forCellReuseIdentifier:@"MyCell"]; } - (void)requestdata
{
NSMutableDictionary *dic =[[NSMutableDictionary alloc]init];
[dic setObject:@"7B63373363386530373034366164393262633633373039326138356238366366307D2C7B336464363563386338626263653130663531623832616632343963363832323065363964656161627D2C7B66616C73657D2C7B307D2C7B307D2C7B66373539333863642D326162352D346232342D616336622D3132386538626434663366397D2C7B37363033396665333533326461623034656561353162363734643131636532617D2C7B323031352D30332D30372031313A31383A33337D2C7B312E382E367D2C7B696F736C6974657261747572657D2C7B494F536C6974657261747572655F312E382E365F696F73382E312E335F6950686F6E65352D327D" forKey:@"sessionKey"];
[dic setObject:@"10" forKey:@"pageSize"];
[dic setObject:@"2" forKey:@"rtype"];
[dic setObject:@"0" forKey:@"pageIndex"];
[dic setObject:@"getLiteraturegroupBySpecialty" forKey:@"m"];
[[HttpManager shareManager] requestWithUrl:KPostUrl withDic:dic WithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { _myModel =[[MyModel alloc] initWithDictionary:responseObject error:nil]; //NSLog(@"%@",responseObject);
[_tabelView reloadData]; NSLog(@"%@",_myModel.numRows);
} WithFailure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 110;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _myModel.obj.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// MyCell *cell =[tableView dequeueReusableCellWithIdentifier:@"MyCell"];
MyCell *cell =[tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
ObjModel *obj=_myModel.obj[indexPath.row]; [cell.psImage sd_setImageWithURL:[NSURL URLWithString:obj.picUrl]];
cell.desLabel.text =obj.descriptionOne;
cell.itemNameLabel.text=obj.itemName;
cell.timeLabel.text=[NSString stringWithFormat:@"%@时%@分%@秒",obj.createDate.hours,obj.createDate.minutes,obj.createDate.seconds]; return cell;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//  AppDelegate.h
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. All rights reserved.
// //Utility:自己封装的类
//libs:第3方库
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; - (void)saveContext;
- (NSURL *)applicationDocumentsDirectory; @end // AppDelegate.m
// JsonModel&AFNetWorking
//
// Created by qianfeng on 15/7/21.
// Copyright (c) 2015年 张国锋. 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. CGRect frame =[[UIScreen mainScreen] bounds];//获取屏幕尺寸
self.window =[[UIWindow alloc]initWithFrame: frame];
self.window.backgroundColor =[UIColor clearColor];
[self.window makeKeyAndVisible]; //让window可见
//以上三句,创建空模板 ViewController *vc =[[ViewController alloc]init];
self.window.rootViewController=vc; return YES;
}

JsonModel&AFNetWorking的更多相关文章

  1. HTTPPost/AFNetWorking/JSONModel/NSPredicate

    一.HTTPPost================================================ 1. POST方式发送请求 HTTP协议下默认数据发送请求方法是GET方式,若需要 ...

  2. 【原】AFNetworking源码阅读(一)

    [原]AFNetworking源码阅读(一) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 AFNetworking版本:3.0.4 由于我平常并没有经常使用AFNetw ...

  3. CocoaPods报错:The dependency `AFNetworking ` is not used in any concrete target

    最近更新了下cocoapods,今天再pod update  就遇到这个错误: 大体意思就是说,库没有用到指定的target. 找了下资料,发现是新版CocoaPods在 Podfile里使用时,必须 ...

  4. 【AFNetworking】AFNetworking源码阅读(一)

    1. 前言 2. iOS Example代码结构 3.AFNetworkActivityIndicatorManager 4. UIRefreshControl+AFNetworking 5. AFN ...

  5. (20170207)开源第三方学习之JSONModel

    1:仓库地址:https://github.com/jsonmodel/jsonmodel   主要作用是把JSON字符串转成Model实体,也可以把实体转化成JSON字符串:还包含一些转字典的内容: ...

  6. AFNetworking 2.0 Tutorial

    Update 1/18/2014: Fully updated for iOS 7 and AFNetworking 2.0 (original post by Scott Sherwood, upd ...

  7. AFNetworking 2.0教程

    在iOS 7中,Apple更新了iOS中的网络基础架构,新推出的网络基础架构是NSURLSession(原来的网络基础架构NSURLConnection). iOS开发中往往会涉及网络数据处理,像其他 ...

  8. 【原】AFNetworking源码阅读(六)

    [原]AFNetworking源码阅读(六) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这一篇的想讲的,一个就是分析一下AFSecurityPolicy文件,看看AF ...

  9. 【原】AFNetworking源码阅读(五)

    [原]AFNetworking源码阅读(五) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇中提及到了Multipart Request的构建方法- [AFHTTP ...

随机推荐

  1. 每天一个linux命令(1):man命令

    版权声明 更新:2017-04-19博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Linux下命令man. 2 ...

  2. bzoj 4503 两个串 快速傅里叶变换FFT

    题目大意: 给定两个\((length \leq 10^5)\)的字符串,问第二个串在第一个串中出现了多少次.并且第二个串中含有单字符通配符. 题解: 首先我们从kmp的角度去考虑 这道题从字符串数据 ...

  3. WPF DatePicker 的textbox的焦点

    要得到DatePicker的textchange属性, 必须通过TextBoxBase.TextChanged 事件来处理. 想要判断是否当前DatePicker的textbox获取到焦点, 可以通过 ...

  4. Ubuntu vim使用

    vim安装:apt-get install vim-gtk vim使用:默认启动插入模式,或者按‘I’进入插入模式,退出插入模式按‘esc’,用冒号‘:wq’进行保存退出: 其复制和粘贴是靠鼠标右键中 ...

  5. GBK点阵显示字库的制作和使用

    转自:http://blog.csdn.net/exbob/article/details/6539643 GBK编码共收录汉字21003个.符号883个,并提供1894个造字码位,简.繁体字融于一库 ...

  6. NancyFX 第一章 NancyFX 简介

    Nancy是.NET 平台的微框架.在受到Ruby社区的Sinatra框架启发下,NancyFx框架提供一个.NET平台下的低门槛.易上手的可用于Web开发工具包. 请注意我说的是可用于Web开发,这 ...

  7. Excel解析easyexcel工具类

    Excel解析easyexcel工具类 easyexcel解决POI解析Excel出现OOM <!-- https://mvnrepository.com/artifact/com.alibab ...

  8. 卡内操作系统COS

    https://wenku.baidu.com/view/dbaa94916bec0975f465e2e8.html 智能卡与cos技术简析: http://www.360doc.com/conten ...

  9. 如何让div中的span垂直居中 ----height:100%设置div的高度

    如果div中只有一个span一个元素,可以使用line-height.如果div中还有其他元素,可以设置span的css如下: .span{ position: absolute; top: 50%; ...

  10. pandas基础(3)_数据处理

    1:删除重复数据 使用duplicate()函数检测重复的行,返回元素为bool类型的Series对象,每个元素对应一行,如果该行不是第一次出现,则元素为true >>> df =D ...